Data Types are made on the basis of how data are stored and how it is accessed.
Primitive Data Types: | (Call By Value ⇒ Changes are made in Copy)
'Hello'
, "World"
).42
, 3.14
).9007199254740991n
).true
or false
.Total 7 Data Types in Primitive Classification.
Non-Primitive (Reference) Data Type: | (Call By Reference ⇒ Changes in the Original Values)
{ name: "John" }
).These are the most basic data types in JavaScript.
Number: Represents numerical values, both integers and floating-point numbers.
let age = 25;
let price = 99.99;
String: Represents textual data, enclosed in single ('
) or double ("
) quotes or backticks (`).
let name = "John";
Boolean: Represents true
or false
.
let isLoggedIn = true;
Undefined: A variable that has been declared but not assigned a value.
let x;
console.log(x); // undefined
Null: Represents an explicitly empty or unknown value.
let data = null;
Symbol: Introduced in ES6, used to create unique identifiers.
let sym = Symbol("id");
BigInt: For numbers larger than 2^53 - 1
(safe integer limit).
let bigNumber = 123456789012345678901234567890n;