Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notes about the typeof operator #344

Open
lewisje opened this issue May 29, 2016 · 0 comments
Open

notes about the typeof operator #344

lewisje opened this issue May 29, 2016 · 0 comments

Comments

@lewisje
Copy link

lewisje commented May 29, 2016

It looks odd that in the Type column, only "number" is in orange, rather than red.

I forget when this happened, but Nitro and V8 now return "object" instead of "function" for regular expressions.

Also, it should be noted that typeof null === "object"; and the spec authors have not been able to fix it without breaking existing code, and it might be noted that in older versions of IE, certain host objects can have the typeof value "unknown" and apparently "date" (although I've never figured out what values have that typeof value), even though MSDN does not mention these; also in those older versions of IE, some DOM methods have the typeof value "object" and do not have the Function.prototype methods, even though, as callable objects, they are functions (as with the previous note, this might complicate things unnecessarily).

A more minor issue is that typeof also returns "undefined" for the undefined value, not just for undeclared variables; an oddity from the HTML5 spec is that if document.all is implemented (for compatibility with oldIE), it must also have the typeof value "undefined", and an ES6-specific change is that if typeof is used on a let- or const-declared variable inside its scope, but before the declaration is reached (that is, in the Temporal Dead Zone, or TDZ), it will throw a ReferenceError.

Finally, another ES6-specific addition is that symbols have the typeof value "symbol" and the [[Class]] property "Symbol"; because the Symbol constructor may not be constructor-called, a Symbol wrapper object would be created with new Object(Symbol()), and as expected, its [[Class]] property is "Symbol" and its typeof value is "object".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant