Primitive and Non Primitive Data Types
Primitive and Non Primitive Data Types in Javascript
Data types are the building blocks of any programming language.We need space to store our data.
In any programming language, we have two types of data type —
- Primitive Data Types
- Non Primitive Data Types
1. Primitive Data Types
Primitive Data Types are the one which only store one value at a time. Example — Storing a value in a variable , that value can number,string , undefined etc.
2. Non Primitive Data Types
Non Primitive Data Types are those which can store multiple values of different types. Example — Storing data in array and object.
Storage Mechanism of Primitive and Non Primitive Data Types
- Primitive Data Types
When we create a variable in Javascript , a room is created with the name of that variable at the door and value of that variable is stored inside the room.
Storage representation of Primitive Data Type
2. Non Primitive Data Types
When we create a non primitive data type (like object) , two things happen , a block and a room gets created.
Block stores the data of the object and have a unique address whereas room stores the address of the block with the name of the object on the door.
Memory Representation of Non Primitive Data Types