I really like the idea of declaring a variable directly in the conditional itself. Many other languages do it. It's certainly not a critical thing (it makes 2 lines of code into 1) but I certainly would like it to happen. Considering it only moves the declaration I'm not convinced it makes code harder to read; in fact since you are explicitly saying it's part of the conditional you're declaring it in I feel like that makes it more clear as there is no longer a risk of someone re-using that variable outside of, say, the while loop it's declared in (which is what can happen today).
I know we don't have voting but this sure has my vote. I'd love to see it championed at an upcoming meeting. On Thu, Sep 15, 2016 at 9:22 AM, Andy Earnshaw <[email protected]> wrote: > How so? Assignment is already possible in control structures. I think > this reads better: > > ``` > if (let a = foo) { > ``` > > Than: > > ``` > let a; > > //... > > if (a = foo) { > ``` > > Having the `let` or `const` inside the conditional part clarifies the > intent. There's an argument for not doing assignment inside the conditional > part, but it's subjective and people will write code that way regardless. > I'd much rather see `let` or `const` next to code like that if it means > mistakes are less likely to be made. > > > On Thu, 15 Sep 2016, 15:17 Mark Volkmann, <[email protected]> > wrote: > >> For what it's worth, I'm on the side of people that do not want to see >> assignment statements in control structures. I don't think it is necessary >> and it results in code that is harder to read. >> >> On Wed, Sep 14, 2016 at 8:51 PM, Alan Johnson <[email protected]> wrote: >> >>> What about `else if`? >>> >>> On Sep 14, 2016 9:28 PM, "Bergi" <[email protected]> wrote: >>> >>>> Danielle McLean wrote: >>>> >>>> variables declared >>>>> using `let` or `const` would be scoped to the individual `if` or >>>>> `while` >>>>> statement, rather than the containing block. In other words, the above >>>>> syntax >>>>> would be equivalent to the following currently-valid form I ended up >>>>> writing: >>>>> >>>>> { >>>>> const oldValue = _.get(object, 'some.long.path'); >>>>> if (oldValue) object.some.long.path = transform(oldValue); >>>>> } >>>>> >>>> >>>> What about `else` blocks, would the variables be available in them as >>>> well? >>>> >>>> - Bergi >>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> >> -- >> R. Mark Volkmann >> Object Computing, Inc. >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

