javascript - JSLint 对三元运算符发出警告

标签 javascript ternary-operator jslint

我在 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/

相关文章:

javascript - 拉斐尔JS : arrow's end and start have different color than the path itself

javascript - 如何解决混合内容问题

javascript - Electron :将应用程序图标添加到任务栏的右下角

javascript - 访问其父项被隐藏的元素 - cypress.io

c++ - 三元运算符 : Compiler does not emit return reference of local variable warning

java - 括号应该总是放在三元运算符周围吗?

java - 三元与 if 在 Java 中

javascript - 对对象(不是数组)使用 for 循环的替代方法是什么?为什么?

javascript - 如何在 JavaScript 中将很长的正则表达式拆分为多行?

jquery - JSLint 显示了很多错误,但我的程序运行良好