The typeof Keyword

By: Dusty Arlia
Published on September 25, 2012
Last Updated on Thursday, July 16, 2015 at 10:21 PM
Total Updates: 4

If you are ever working with a variable and would like to know its data type (number, string, Boolean, etc.) you can use the typeof operator to figure it out. Here is an example of how to figure out the data type for the variable named luckyNumber:

var luckyNumber = 8;
alert(typeof luckNumber);

In this example, the word "number" will appear in the alert window.