Proposal: anaphoric if and while syntax

Danielle McLean gopsychonauts at
Thu Sep 15 05:12:28 UTC 2016

"Bergi" <a.d.bergi at> wrote:

> What about `else` blocks, would the variables be available in them as well?

No. If the `else` block executes, then the variable's value would be
falsy and therefore presumably not useful for further processing. Of
course, there are multiple falsy values in ES, but knowing which
specific falsy value a condition produced is far less useful than
knowing which specific truthy value a condition produced.

If you've got a use case for the variable's scope extending into the
`else` block, though, feel free to change this. ;)

"Alan Johnson" <alan at> wrote:

> What about `else if`?

As with a standalone `else`, the `else if` branches are only reached
if the value from the `if` branch was falsy and therefore presumably
not useful. So, again, the variable from the original `if` condition
need not be available.

It should however be possible to declare *another* variable in an
`else if`'s condition, for consistency. Like this:

if (const x = expr()) {
  // use x
} else if (const x = expr2()) {
  // use x in a different way
} else {
  // couldn't get either kind of x :(

More information about the es-discuss mailing list