Javascript Datatype

JavaScript has basically two type of datatypes
1) Primitive Datatype
2) Composite Datatype

1) Primitive Datatype:- These type of datatype is immutable and it do not have properties. When you make a copy, it will be a real copy.

Example:- when you reassign a new value to b, the value of b changes, but not of a.

 const a = "John";
 let b = a   // this is the copy
 b = "Rom";
 document.write(b) // Rom
 document.write(a) // John

Try it Yourself

1) String:- It is basically used to store string value and string value represents through single quote or double quotes.

 var name="John";
 console.log(typeof name);  //string

2) Number:- It is used to store number value.

 var age=35;
 console.log(typeof age);  //number

3) undefined:- A variable that has not value is undefined.

  var name;
  console.log(typeof name); // undefined 

4) Null:- It has null value.

 var nothing = null;

5) Boolean:- this datatype variable has value true or false.

 var is_loggedin=true;
 console.log(is_loggedin);  //true

 var not_loggedin=false;
 console.log(not_loggedin);  //false

6) Symbol:- It came into ECMAScript6 (ES6). It represents a unique identifier.

2) Composite Datatype:- Object, Array and methods are compositive datatypes. Technically, arrays are also objects, so they behave in the same way. These values are actually stored just once when instantiated, and assigning a variable just creates a pointer (reference) to that value.

Object Example:-

 var users={

 console.log(typeof users) //Object

Array Example:-

 var users=[{

 console.log(typeof users) //Object

Example:- Now, if we make a copy b = a , and change some nested value in b, it actually changes a’s nested value as well, since a and b actually point to the same thing.

 const a = {name:'John'}
 const b=a;'Rom';
 document.write(;  //Output:- Rom
 document.write(;  //Output:- Rom

Try it Yourself