I\'m reading \'Professional Javascript for Web Developers\' Chapter 4 and it tells me that the five types of primitives are: undefined, null, boolean, number and string.
If
null
is a primitive, why doestypeof(null)
return"object"
?
Because the spec says so.
11.4.3 The
typeof
OperatorThe production UnaryExpression :
typeof
UnaryExpression is evaluated as follows:
- Let val be the result of evaluating UnaryExpression.
- If Type(val) is Reference, then
a. If IsUnresolvableReference(val) is true, return "undefined
".
b. Let val be GetValue(val).- Return a String determined by Type(val) according to Table 20.