4 ms·
I'm down if you require a let/var/const in front of it: if (foo = bar()) { // syntax error! } if (let foo = bar()) { // works fine } if (
by ubertaco 7y ago
I'm down if you require a let/var/const in front of it:
if (foo = bar()) { // syntax error!
}
if (let foo = bar()) { // works fine
}
if (const foo = bar()) { // also works fine
}
if (var foo = bar()) { // also also works fine
}
- fenomas 7y ago> if (foo = bar()) { // syntax error! That's already an error in strict mode (which would presumably be on for anyone writing bleeding-edge JS).
- AgentME 7y agoIt's only an error in strict mode if there's no variable in scope named foo.
- dotancohen 7y agoAnd what if foo had already been defined in the scope?
- munificent 7y agoThe new one shadows it.
- dotancohen 7y agoLocal 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;