11.4.3 typeof operator

2010-05-16

UnaryExpression : typeof UnaryExpression

Code: (Meta Ecma)
function evaluate(typeof UnaryExpression) {
if (Type(val) == Reference) {
if (IsUnresolveableReference(val)) return "undefined";
val = GetValue(val);
}
switch (Type(val)) {
case "undefined": return "undefined";
case "null": return "object"; // !!
case "boolean": return "boolean";
case "number": return "number";
case "string": return "string";
default: // object
if ([[Call]] in val) return "function"; // for native and host objects...
if (val.[[Constructor]] === Object) return "object"; // "native object"?
// host object..
return "implementation defined value"; // may not be "undefined", "boolean", "number" or "string"
}
}

Note that typeof null is "object". Host objects may not return any of the native primitive types, except for null, to prevent confusion. Unresolvable Identifiers will return "undefined" and not throw a SyntaxError.