But when a value is assigned to a variable for first time it attains the data type according
to the value stored in it.
For example
var name= " Naveed"; //now name is string
var num= 55; //now it is an integer.
so that
var number=num+45; //output is just 100
var number=name+num; // output is meaningless and will be 55Naveed
some more examples
var length = 16; // Number
var lastName = "Johnson"; // String
var x = {firstName:"John", lastName:"Doe"}; // Object
person = null; //Null values is assigned
x===y // boolean false or true
typeof functions return the data type of the variable which it holds as shown in below screen shot.
for example
typeof lastName //Returns string
typeof number // Return Number
typeof "John" // Returns "string"
typeof 3.14 // Returns "number"
typeof true // Returns "boolean"
typeof false // Returns "boolean"
typeof x // Returns "undefined" (if x has no value)