4 ms·
Oscar, when your code itself is making little frowny faces at you after you write it, something has gone wrong. x == 1 ? alert(x) :( alert('Error')
by mquander 15y ago
Oscar, when your code itself is making little frowny faces at you after you write it, something has gone wrong.
x == 1
? alert(x)
:(
alert('Error'),
x = 1,
alert('All Fixed!')
);
- scarmig 15y agoDoes javascript guarantee a particular order of expression evaluation when there aren't any sequence points? Alerting 'All Fixed' and afterwards 'Error' seems like it'd be just as valid an interpretation of the code. Edited to add: Actually, I think the comma operator does do that, so no bad. Though the code is still unsightly...
- ryankshaw 15y agolol, after reading the article I came back in here to call out that exact same chunk of code and the exact same sad face. I will agree, however for small things the ternary operator is prettier than the if...then...else... syntax thing[conditional ? 'show' : 'hide'](); instead of: thing[if conditional then 'show' else 'hide']()
- checker 15y agoPython makes little frowns at the end of conditionals and loops that call functions or have sets of boolean logic ):