Data Types

JavaScript has five simple data types also called primitive types - Number, String, Boolean, Null, Undefined - and one complex data type called Object which contains a list of name-value pairs.

typeof Operator

Since JavaScript does not have a way to define the data type of the variable, it is important to determine the data type of the variable. The typeof operator can be used to find out the type of the variable. The typeof operator returns one of the following data type.

The typeof operator can be used in the following way.


    var number = 10;
    var result1 = typeof(number); //number
    var result2 = typeof number; //number
    var result3 = typeof "number"; //string

Note that typeof is an operator and not a function and so the parenthesis is not required but it can be used. The only issue that can arise using the typeof operator is when the data type is null. When the value is null, typeof operator returns "object" as the null is an empty object reference.