Difference between Primitive and non-primitive datatypes in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

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
raja
Published on 12-Sep-2020 08:05:40
Advertisements