do while scope

Glen Huang curvedmark at gmail.com
Fri Apr 17 15:36:03 UTC 2015


Thank you.
 
I just post my new understanding a few seconds earlier. Hope that's right. :)

> On Apr 17, 2015, at 11:28 PM, Andreas Rossberg <rossberg at google.com> wrote:
> 
> On 17 April 2015 at 17:18, Glen Huang <curvedmark at gmail.com <mailto:curvedmark at gmail.com>> wrote:
> Not sure about others, but i assume the condition part and statement part in a control construct live in the same scope.
> 
> That's why you can do `for (let a = 1; a < 2; a++) a;`. And `if (let a = 1) a;` maybe in es7?
> 
> Why that's not the case for "do while"? Is my mental model wrong?
> 
> Yes. :)
> 
> for (let x ...) scopes over the body naturally. In your example, you expect to scope an inner declaration (one even inside a block) to scope to the outside. That is something else entirely, and makes no sense to me.
> 
> /Andreas
> 
> 
> > On Apr 17, 2015, at 11:10 PM, Caitlin Potter <caitpotter88 at gmail.com <mailto:caitpotter88 at gmail.com>> wrote:
> >
> > Is there a language where lexically scoped variables declared in a block are accessible outside of that block? Java, C, C#, rust, Python, etc, will not let you do this. I’m not sure this is a gotcha for most software developers
> >
> >> On Apr 17, 2015, at 10:57 AM, Glen Huang <curvedmark at gmail.com <mailto:curvedmark at gmail.com>> wrote:
> >>
> >> ```js
> >> do {
> >> let a = 1;
> >> } while (a);
> >> ```
> >> is "a" undefined in the while condition? This seems like a gotcha.
> >>
> >>
> >> _______________________________________________
> >> es-discuss mailing list
> >> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> >> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
> >
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150417/9be5e2fd/attachment.html>


More information about the es-discuss mailing list