Hoisting behaviour of 'const' and 'let'

Yuh-Ruey Chen maian330 at gmail.com
Sat Oct 11 21:00:32 PDT 2008


David-Sarah Hopwood wrote:
> Mark S. Miller wrote:
> > On Sat, Oct 11, 2008 at 4:01 PM, Brendan Eich <brendan at mozilla.com> wrote:
> >>> If we want to avoid the read-barrier, we should not hoist either const
> >>> or let. If we are to consider not hoisting const, WE NEED TO DECIDE
> >>> THIS NOW, before ES3.1 mandates a hoisting const.
> >>
> >> A few messages back you nicely repeated the
> >> least-concepts/least-astonishment/most-symmetric case for hoisting to block
> >> top that has carried so far. I don't see how we can backtrack here. We'll
> >> flail hard.
> >> [...other good stuff snipped...]
> > 
> > I'm convinced; thanks. I agree it's too late to consider non-hoisting
> > const even if we come to regret it. Given that const hoists, let
> > declarations must as well, and we can argue about let-read-barriers
> > and repeated declarations later.
>
> I disagree with this reasoning.
>
> The reason for making 'const' hoist to the top of the enclosing block,
> AFAIR, was consistency with function declarations. However, there are
> good reasons why 'const'/'let' and function declarations should be
> treated differently:
>
> <snip>

I think you're forgetting about |var| hoisting. |const| and |let| should
be compared with |var|, not just function declarations. And if |var|
hoists, yet |const| and |let| do not, it's inconsistent.

Honestly though, this is an inconsistency I could live with.


More information about the Es-discuss mailing list