Normally when we hear data types in any programming language, integer, string, etc... jumps to our mind.
Although all of these things are data types, there are two umbrellas contains most of the JavaScripts data types.
Primitive Data Types & Non Primitive Data Types
Non Primitive Data Types
- Array which is used for storing different elements, Ex:
arr = [1, 3, 5, 'jack']
- Object which is a standalone entity, with properties and type, Ex:
client = {
name: "Harry Potter",
age: 20,
eyeColor: "blue"
};
Primitive Data Types
- Number which is used for floating-point numbers, Ex:
num = 1;
- String which is used for sequence of characters, Ex:
name = 'Mike';
- Boolean which is used for logical type that can be only true or false, Ex:
flag = true;
- Undefined which is used for a variable that got declared and yet not assigned to a value (empty value), Ex:
value;
console.log(value) // undefined
- Symbol (ES2015) which is used for value that is unique & cannot be changed, Ex:
client = {
name: "Harry Potter",
age: 20,
eyeColor: "blue"
};
id = Symbol('id');
client[id] = 101959; // you added an id to client named 'Harry Potter'
- BigInt (ES2020) which is used for larger integers than the number type can hold, Ex:
bigNum = BigInt("123456789012345678901234567890123456789");
Note:
in both the array & the object can contain different types of data.
Top comments (2)
You've missed
null
in the primitive typesyeah thanks for reminding me