typeof
suggest changetypeof 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”
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents