The Difference Between a Primitive Datatype and a Non-primitive Datatype

Jagan mohan
Nov 5, 2020

Primitive Datatype

Primitive values and object references are stored in JavaScript programs in different ways.

When a primitive value is assigned to a variable (eg. let toy = ‘ball’), variable is given with the value Directly.

Non-Primitive Datatype

When the variable is assigned with an object, however, things are different. When compared with primitive Datatype it does not assign value to the variable Directly it has only contain reference to it . Here’s an example:

const sebi= {

name: ‘Mehta’,

occupation: ‘Stock Broker’,

}

With the above code, JavaScript creates the object and stores it in computer memory. The variable sebi does not contain the new object directly, it contains a reference to the memory address that currently stores the object.

--

--

Jagan mohan

Strings,Booleans can be classified as primitive data types whereas Arrays and Objects are composite data types