Since ECMAScript is loosely typed, there is a need to have a means to detect the data type of a given variable--typeof is the operator responsible for providing this convenient information. Using the typeof operator on a value may return one of the following strings:
"Undefined"--if this value is not defined
"Boolean"--if this value is a Boolean value
"String"--if this value is a string
"Number"--if this is a numeric value
"Object"--if this is an object or null
"Function"--if this value is a function
Here are a few examples of using the TypeOf operator:
var message = "some string";
Alert (typeof message); "String"
Alert (typeof (Message)); "String"
Alert (typeof 95); "Number"
These examples show that the operands of the typeof operator can be either a variable (message) or a numeric literal. Note that TypeOf is an operator rather than a function, so the parentheses in the example are not required (although they can be used).