typeof

suggest change

typeof is an operator, not a function. Parentheses around the operand are grouping, not a call. Some results are surprising:

\1. Strings

typeof "String" is "string".

Date(2011, 1, 1) ignores those arguments and returns a string, so typeof Date(2011, 1, 1) is also "string". typeof new Date() is "object".

\2. Numbers

typeof 42

“number”

\3. Bool

typeof true (valid values true and false)

“boolean”

\4. Object

typeof {} or

typeof [] or

typeof null or

typeof /aaa/ or

typeof Error()

“object”

\5. Function

typeof function(){}

“function”

\6. Undefined

var var1; typeof var1

“undefined”

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents