In this tutorial we are going to discuss JavaScript variables that can hold many data types. There are two types of JavaScript data types Primitive and Non-Primitive. Primitive includes six data types (As per ECMAScript 6)
- Null
- Undefined
- Boolean
- Number
- String
- Symbol
The Non-Primitive data type includes Object,Array and RegExp(Regular Expression). To describe Non-Primitive data type require seperate post for each so in upcoming tutorials we will learn Object,Array and RegExp .
Primitive data type
Data Type | Description / Reference |
---|---|
NULL | NULL means no value at all |
Undefined | Undefined means undefined value like 20/0 |
Boolean | Boolean means either false or true |
Number | Number represents numeric values e.g. 100 |
String | Number represents sequence of characters e.g. “hello 2345 #%” |
Symbol | A symbol is a unique and immutable data type and may be used as an identifier for object properties. The symbol object is an implicit object wrapper for the symbol primitive data type. |
Non-Primitive data type
Data Type | Description / Reference |
---|---|
Object | represents instance through which we can access members |
Array | represents group of similar values or data types |
RegExp | represents regular expression |
Remember : JavaScript is a dynamic type language, means you don’t need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc.
For Example:
<script>
var x=50; //holding number represent number
var b="JavaScript is Dynamic"; //holding string
</script>