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?
UPDATE: This answer is outdated now. Apparently Crockford changes his mind ;)
See @CheapSteaks's answer for the update.
Per Crockford:
So:
If you run this sample code through JSHint, this will pass:
This works and is certainly valid. It's especially useful in more complicated use cases, like nested ones.
Per Crockford
You should put the operator on the end of the line. That way its more clear that the statment continued to the next line.