I have the following code in JavaScript:
var a = num ? 5 : "five";
Code seems to be workable. But JSLint warns like this:
#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 the problem is? How to disable such warnings?
I have the following code in JavaScript:
var a = num ? 5 : "five";
Code seems to be workable. But JSLint warns like this:
#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 the problem is? How to disable such warnings?
Share Improve this question asked Jan 28, 2016 at 16:36 fbjornfbjorn 9001 gold badge14 silver badges30 bronze badges 3-
2
Is your indentation correct? Found this online:
"With JSLint you'll get an "Expected '{a}' at column {b}, not column {c}" error any time an incorrect indentation width is found."
– IrkenInvader Commented Jan 28, 2016 at 16:39 -
Seems like you should put more code in here, currently, your
?
is at column11
. – Loïc Faure-Lacroix Commented Jan 28, 2016 at 16:41 - When I place it to begin of the line: #2 Undeclared 'h'. var a = h ? 5 : "qwerty"; // Line 4, Pos 9 #3 Expected '?' at column 5, not column 11. var a = h ? 5 : "qwerty"; // Line 4, Pos 11 Indentation is 1:1 like in question. – fbjorn Commented Jan 28, 2016 at 16:44
1 Answer
Reset to default 11Its opinion is that:
The ternary operator can be visually confusing, so
?
question mark and:
colon always begin a line and increase the indentation by 4 spaces.var a = h ? 5 : "qwerty";
To fix either ply with the rule or tick messy whitespace.