我在 JavaScript 中有以下代码:
var a = num ? 5 : "five";
代码似乎是可行的。但是 JSLint 会这样警告:
#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
那么问题是什么?如何禁用此类警告?
最佳答案
它的观点是:
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";
要修复,请遵守规则或勾选杂乱的空格。
关于javascript - JSLint 对三元运算符发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35066980/