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

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jagan mohan

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