-
Notifications
You must be signed in to change notification settings - Fork 797
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
Can typeof be used with block-bound variables #49
Comments
It prints "undefined" in sloppy mode and throws a ReferenceError in strict mode. Spec sections:
|
It is quite surprising that "use strict";
console.log(typeof a);
console.log(typeof b); // ReferenceError
let b = 2; Wouldn't it have made more sense for it to behave the same in both cases? What's the justification for the error in the |
The let global = this;
Object.setPrototypeOf(global, new Proxy(Object.create(null), {
_has: false,
has(t, pk) {
// Switch the HasBinding() result for the global object environment on every access
return this._has = !this._has;
}
}));
typeof a; // undefined
"use strict"; typeof a; // ReferenceError |
Thanks for the clarification, but I was actually asking the reverse question. Perhaps I'm missing it, but I'm not sure I understand why there needed to be an error on To put it another way, I see it as a feature, not a bug, that It would seem at quick glance that being able to do similar checks in a safe way against TDZ'd |
Thanks @anba for the explanation. Seems like some good fodder for es-discuss. |
The |
Dunno what if anything will come of it, but I filed this as a ES6 bug: https://bugs.ecmascript.org/show_bug.cgi?id=3009 |
This came up on #48, should this throw an error or not?
@getify @rwaldron
The text was updated successfully, but these errors were encountered: