Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign uplet/const/class allow local binding of "undefined" #830
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
NE-SmallTown
commented
Mar 2, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bakkot
Mar 2, 2017
Contributor
@NE-SmallTown, at the top level they're prohibited because they're restricted globals. Allen is observing that they're not restricted elsewhere: { let undefined; } is legal.
|
@NE-SmallTown, at the top level they're prohibited because they're restricted globals. Allen is observing that they're not restricted elsewhere: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
NE-SmallTown
Mar 2, 2017
@bakkot Sorry for the cursory test.I test again,Allen is right,it does questionable.
NE-SmallTown
commented
Mar 2, 2017
|
@bakkot Sorry for the cursory test.I test again,Allen is right,it does questionable. |
allenwb
changed the title from
let/const/class allow binding of "undefined"
to
let/const/class allow local binding of "undefined"
Mar 2, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Mar 2, 2017
Member
I recall raising this back in the day but the thinking was it's fine since you can't redeclare undefined and you can only look up to an undefined binding in your own code (so it is much less bad than ye olde undefined = true). I'm ok fixing it still :)
|
I recall raising this back in the day but the thinking was it's fine since you can't redeclare undefined and you can only look up to an undefined binding in your own code (so it is much less bad than ye olde |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Mar 2, 2017
Member
It seems similar, to the strict mode restriction on redeclaring eval and arguments. It just shouldn't be allowed.
|
It seems similar, to the strict mode restriction on redeclaring |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Is this something that could be a Needs-Consensus PR? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Apr 4, 2018
Member
For the reasons in #830 (comment) , I am not convinced this is a problem.
|
For the reasons in #830 (comment) , I am not convinced this is a problem. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Apr 5, 2018
Contributor
Note that undefined is not alone in that case, as other ”global constants”, namely NaN and Infinity, may be locally rebound as well.
(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)
|
Note that (BTW, I wonder why |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
claudepache
Apr 5, 2018
Contributor
(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)
(Ok, I guess that window.eval = function(x) { throw new EvalError; } /* let’s remove dangerous toys! */ is reasonable, but window.Infinity = 2038; /* it’s distant enough! */ is not.)
(Ok, I guess that |

allenwb commentedMar 1, 2017
•
edited
I was rather shocked today to discover that since their introduction in ES2015
let,const,classand other new binding forms have allowedundefinedto be used as a local binding identifier. Even in strict mode.I think this was an oversight in ES2015. In ES5 we made the global property "undefined" non-configurable and non-writable. But we did not prevent
varandfunctiondeclarations from bindingundefined. This was necessary because there were widely used coding patterns where the mutability of the global "undefined" property was mitigated by usingvarto redeclareundefined.But,
let/const/classwere new constructs in ES2015 and that backwards compat constraint should not have applied to them.I don't know if we could get away with fixing this now but I think we should at least investigate the possibility.