You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree that multi-line ternary operators make sense. However, the following is (as far as I know) bad, due to ASI:
var foo = (a === b)
? 1
: 2;
JShint will throw an error on this code, saying “Bad line breaking before '?'”.
If you insist on using multi-line ternary operators, you might prefer the following style:
var foo = (a === b) ?
1 :
2;
I agree that it is less readable, because the question mark and the colon are more obvious at the beginning of the line. But I wouldn’t want to mess with ASI and depend on implicit fixes of the JS engine, either.
The text was updated successfully, but these errors were encountered:
@rumkin this is not an issue of JSHint but rather of JS specs vs. what browsers allow. If browsers would strictly follow the specs in this case and apply ASI, the ternary operator in the first example would cause a syntax error at the second line.
I agree that multi-line ternary operators make sense. However, the following is (as far as I know) bad, due to ASI:
JShint will throw an error on this code, saying “Bad line breaking before '?'”.
If you insist on using multi-line ternary operators, you might prefer the following style:
I agree that it is less readable, because the question mark and the colon are more obvious at the beginning of the line. But I wouldn’t want to mess with ASI and depend on implicit fixes of the JS engine, either.
The text was updated successfully, but these errors were encountered: