Since ECMAScript is loose, there is a need to detect the Data Type of a given variable-typeof is the operator responsible for providing this convenient information. Using the typeof operator for 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 the value is a string
"Number" -- if this value is a numerical value
"Object" -- if this is an object or null
"Function" -- if this value is a function
Below are several 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 operand of the typeof operator can be a message or a numeric literal. Note that typeof is an operator rather than a function, so parentheses in the example are not required (although they can be used ).