Home >>Javascript Tutorial >Javascript Data Types

Javascript Data Types

Javascript Data Types

To hold different types of values, JavaScript provides different data types. In JavaScript, there are only two types of data types:

  • Primitive data type
  • Non-primitive (reference) data type

JavaScript is generally known as a dynamic type language that means there is no need to specify the type of variable as it is dynamically used by the JavaScript engine. In order to specify the data we have to use var keyword. This can hold any type of values e.g. strings, number and more.

1. Primitive data types in JavaScript

In JavaScript, there are five types of primitive data types as depicted below:

Data Type Description
String This represents the sequence of characters e.g. "hi"
Number This represents the numeric values e.g. 130
Boolean This represents the boolean value whether it is either false or true
Undefined This represents the undefined value
Null This represents the null i.e. no value present.


var x=20;//holding number  
var y="Phptpoint";//holding string  
var bool=true;//holding boolean true
var bools=false;//holding boolean false 
var blank=null;//holding null value

2. Non-Primitive Data Types in JavaScript

There are generally three types of non-primitive data types which are as follows:

Data Type Description
Object This data type represents the instance through which the members can be accessed.
Array This represents a group of similar values
RegExp This represents a regular expression

Example of Object:

//example of Object 
alert(stu.id+" "+stu.name);  

Example of Array:

//example of Array 
alert(arr[0]+" "+arr[1]);  

No Sidebar ads