Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  158] [ 1]  / answers: 1 / hits: 25453  / 13 Years ago, wed, august 31, 2011, 12:00:00

I really like aligning the ? and the : of my ternary operator when they don't fit on a line, like this:



var myVar = (condition
? ifTrue
: ifFalse
);


However, JSHint complains with:




Bad line breaking before '?'




Why would JSHint have this warning? Is there any nastyness (like semicolon insertion, etc) it is protecting me against or can I safely change my JSHINT configuration to ignore it?


More From » jshint

 Answers
85

This works and is certainly valid. It's especially useful in more complicated use cases, like nested ones.



var a = test1
? b
: test2
? c
: d;

[#90330] Monday, August 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trinity

Total Points: 591
Total Questions: 102
Total Answers: 106

Location: Singapore
Member since Sun, Jul 25, 2021
3 Years ago
;