If
nullis a primitive, why doestypeof(null)return"object"?
Because the spec says so.
11.4.3 The
typeofOperatorThe production UnaryExpression :
typeofUnaryExpression 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.
