Re:What’s New in ES2019
by ubertaco on Tuesday July 30, 2019 @10:55AM
(#20565353)
I'm down if you require a let/var/const in front of it:
[ Parent
| on HN ]
> if (foo = bar()) { // syntax error!
That's already an error in strict mode (which would presumably be on for anyone writing bleeding-edge JS).
It's only an error in strict mode if there's no variable in scope named foo.
Re:What’s New in ES2019
by dotancohen on Tuesday July 30, 2019 @12:43PM
(#20566592)
And what if foo had already been defined in the scope?
Re:What’s New in ES2019
by munificent on Tuesday July 30, 2019 @01:25PM
(#20567016)
The new one shadows it.
Re:What’s New in ES2019
by dotancohen on Wednesday July 31, 2019 @08:54AM
(#20574002)
Local scope might not be what the programmer wants, though, depending on circumstance. Pseudocode:
i = 3;
foo = \0;
while ( i-- ) {
if ( foo = resultFromFooApi() ) {
break;
}
sleep 1;
}
return foo;