Javascript Datatypes

Value store in a variable is of some datatype. There are the five primitive datatypes in Javascript.


Boolean has only two possible values either TRUE or FALSE. Boolean is used in many condition code statements. Comparison operator always returns a boolean value. We can also check the boolean value of other data types by using the boolean casting function. Like All non zero integers and floating values are TRUE, a blank string boolean value is false.

var str = '';
var str1 = 'Hello World';
var boostr = Boolean(str); 
alert(boostr); // it alerts false
var boostr1 = Boolean(str1); 
alert(boostr1); // it alerts true


Javascript support all integers and floating points as number data types.

var a1 = 10;
var a2 = 10.00;    

All are valid number data types.

Javascript also support octal and hexadecimal numbers.

var a3 = 062 // Octal value of a number 50
var a4 = 0xA // Hexadecimal for 10   


Null data type is an empty object pointer and has only one value 'null'. The below code alert object as output.

var tree = null;
alert(typeof tree);


The string is a sequence of characters enclosed within double and single quotes.

var str1 = 'This is string datatype';
var str2 = 'This is string datatype';    


When a variable is declared using var, but not defined, then by default it is initialized as undefined.

var tree;
alert(typeof tree);


Object is a complicated datatype. This data type is created by using an instance of object.

var obj = new Object();

Read more articles

General Knowledge

Learn Popular Language