JavaScript Operator: typeof
[this page | pdf | back links]
In JavaScript,
the typeof operator returns
the type of a variable, object, function or expression, e.g.
x
|
typeof x
|
false
|
boolean
|
true
|
boolean
|
0
|
number
|
1
|
number
|
"0"
|
string
|
"1"
|
string
|
NaN
|
number
|
Infinity
|
[???]
|
-Infinity
|
[???]
|
""
|
string
|
"10"
|
string
|
"ten"
|
string
|
[ ]
|
object
|
[10]
|
object
|
[5,10]
|
object
|
["ten"]
|
object
|
["five","ten"]
|
object
|
function(){}
|
function
|
{ }
|
object
|
null
|
object
|
undefined
|
undefined
|
The type of a date, array
or null is an object, which means that you cannot directly use the typeof operator to work out if a
JavaScript object is an array rather than a date, say.
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators