What are Data Types?
Data types in JavaScript define the kind of value a variable can hold. They tell the JavaScript engine how to store and handle data.
Types of Data Types in JavaScript
JavaScript has 2 main categories:
- Primitive Data Types (Basic Types)
These store single values and are immutable.
✔ List of Primitive Types:
Number
let x = 10;
let y = 3.14;String
let name = "John";
let city = 'Chennai';
Template literals:
let msg =Hello ${name};
Strings are immutableBoolean
Logical values:
let isActive = true;
let isDone = false;
Used in:
Conditions
ComparisonsUndefined
A variable declared but not assigned:
let x;
console.log(x); // undefinedNull
Represents intentional absence of value:
let data = null;
Difference:
undefined → no value assigned
null → empty on purposeBigInt
For very large numbers:
let big = 123456789012345678901234567890n;
Used when numbers exceed safe limit (Number.MAX_SAFE_INTEGER)Symbol
Creates unique identifiers:
let id1 = Symbol("id");
let id2 = Symbol("id");
console.log(id1 === id2); // false
Always unique
What is Mutable and Immutable?
Mutable
A mutable object can be changed after it is created.
You can modify:
Its values
Its propertiesImmutable
An immutable value cannot be changed after creation.
If you try to change it, you actually create a new value, not modify the original.
*Mutable in JavaScript (Detailed)
In JavaScript, non-primitive types are mutable:
Objects
Arrays
Functions
Example: Object (Mutable)
`let person = {
name: "John"
};
person.name = "Alex"; // modifying existing object
console.log(person.name); // Alex
✔ The original object is changed`
Mutable = same memory location is modified.
*Immutable in JavaScript (Detailed)
Primitive types are immutable:
Number
String
Boolean
Null
Undefined
BigInt
Symbol
Example: String (Immutable)
`let str = "hello";
str[0] = "H"; // trying to change
console.log(str); // "hello"
No change happens`
Top comments (0)