JSLint warns of ternary operator

I have the following code in JavaScript:

var a = num ? 5 : "five"; 

The code seems to be workable. But JSLint warns the following:

 #2 Expected '?' at column 9, not column 15. var a = h ? 5 : "qwerty"; // Line 10, Pos 15 #3 Expected ':' at column 9, not column 19. var a = h ? 5 : "qwerty"; // Line 10, Pos 19 

So what's the problem? How to disable such warnings?

+6
source share
1 answer

His opinion is this:

The ternary operator can be visually confusing, why ? question mark and : colon always starts the line and increases the indent by 4 spaces.

  var a = h
     ?  5
     : "qwerty";

To correct, either abide by the rule or mark promiscuous spaces.

+10
source

All Articles