restrictions on let declarations

Allen Wirfs-Brock allen at
Thu Jan 30 08:05:14 PST 2014

On Jan 30, 2014, at 7:43 AM, John Lenz wrote:

> It seems unfortunate that "let" and "const" have different usage rules from "var".  It seem strange  that "var" is considered a statement and not declaration as per:
> Generally, I've always thought of:
> "if (x) ..." as equivalent to "if (x) { ... }"
> Does this restriction on let/const enable anything?

The anomaly is that 'var' was considered a statement in ES1. But note that the only other declaration in the language ('function') at that time was not a statement. See 

Declarations have global static impact within their containing scope (function or block). It generally doesn't make any sense to use them in a conditional context without an explicitly surrounding block that constrains their scope.

So all new declarative forms in ES6 are treated similarly to function.  They are declarations but not statements.  Var must remain a statement for legacy compatability.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list