The typeof operator evaluates to
"number", "string", or "boolean"
if its operand is a number, string, or boolean value. It evaluates to
"object" for objects, arrays, and (surprisingly)
null. It evaluates to "function" for
function operands and to "undefined" if the operand is
undefined.
typeof evaluates to "object" when its
operand is a Number, String, or Boolean wrapper object. It also
evaluates to "object" for Date and RegExp objects.
typeof evaluates to an implementation-dependent
value for objects that are not part of core JavaScript but are
provided by the context in which JavaScript is embedded. In
client-side JavaScript, however, typeof typically
evaluates to "object" for all client-side objects, just
as it does for all core objects.
You might use the typeof operator in expressions
like these:
typeof i
(typeof value == "string") ? "'" + value + "'" : value
Note that you can place parentheses around the operand to
typeof, which makes typeof look
like the name of a function rather than an operator keyword:
typeof(i)
Because typeof evaluates to "object"
for all object and array types, it is useful only to distinguish
objects from other, primitive types. In order to distinguish one
object type from another, you must use other techniques, such as the
instanceof operator or the
constructor property (see the
"Object.constructor" entry in the core reference
section).
The typeof operator is defined by the ECMAScript
v1 specification and is implemented in JavaScript 1.1 and later.