Home >>Javascript Tutorial >Javascript Data Types
To hold different types of values, JavaScript provides different data types. In JavaScript, there are only two types of data types:
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.
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. |
Example:
<script> 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 <script>
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:
<script> //example of Object stu={id:101,name:"sanjeev"} alert(stu.id+" "+stu.name); </script>
Example of Array:
<script> //example of Array arr=Array(101,"sanjeev"); alert(arr[0]+" "+arr[1]); </script>