[英]JavaScript compiler requires '===' instead of '==' everywhere in Visual Studio
I'm using Visual Studio 2015 and try to update all updates which it needs. 我正在使用Visual Studio 2015并尝试更新它需要的所有更新。
My problem: when I create a new js file, the js compiler would gave me an error eqeqeq
(I don't understand what this code means) whenever I use '=='
to compare. 我的问题:当我创建一个新的js文件时,每当我使用
'=='
进行比较时,js编译器会给我一个错误eqeqeq
(我不明白这段代码是什么意思)。
Example: 例:
// Declaring a number within a default value
var caret_index = 0;
// Now, js compiler should know 'caret_index' type
// alert(typeof(caret_index)); -> number
// alert($.type(caret_index)); -> number
// So,
// Expected '===' and instead of saw '=='
if (caret_index == 0) {
// ...
}
That said: You must use '===' in the
if condition.
那就是说:
You must use '===' in the
if condition.
You must use '===' in the
condition.
Why? 为什么? It just needn't cast
caret_index
to number
before comparing to 0
. 在比较
0
之前,它不需要将caret_index
为number
。
It's not Visual Studio, it's your lint settings. 它不是Visual Studio,它是你的lint设置。 If you don't have a
.eslintrc.json
file in your project root, then create it. 如果项目根目录中没有
.eslintrc.json
文件,则创建它。 Visual Studio will read this to see which rules it should apply. Visual Studio将阅读此内容以查看它应适用的规则。 Look for the triple equals rule:
寻找三等于规则:
"triple-equals": [
false,
"allow-null-check"
]
alternatively, it might be a rule contained in an external file if you have any references under rules directory: 或者,如果您在rules目录下有任何引用,它可能是包含在外部文件中的规则:
"rulesDirectory" :[]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.