Difference Between Primitive and Non-Primitive Data Types in JavaScript



The primitive data types are number, string, boolean, float etc. The non-primitive data types (Reference Type) are Array, Object etc.

Example

var number=10;
var stringValue="John";
var booleanValue=true;
var obj={};
var newArray=new Array();
console.log("The data type is="+typeof number);
console.log("The data type is="+typeof stringValue);
console.log("The data type is="+typeof booleanValue);
console.log("The data type is="+typeof obj);
console.log("The data type is="+typeof newArray);

To run the above program, you need to use the following command −

node fileName.js.

Output

Here, my file name is demo162.js. This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo162.js
The data type is=number
The data type is=string
The data type is=boolean
The data type is=object
The data type is=object
Updated on: 2020-09-12T08:06:44+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements