gpt4 book ai didi

JavaScript 编译器在 Visual Studio 中到处都需要 '===' 而不是 '=='

转载 作者:行者123 更新时间:2023-11-30 11:54:11 24 4
gpt4 key购买 nike

我正在使用 Visual Studio 2015 并尝试更新它需要的所有更新。

我的问题:当我创建一个新的 js 文件时,每当我使用 '== 时,js 编译器都会给我一个错误 eqeqeq (我不明白这段代码是什么意思) ' 进行比较。

例子:

// 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) {
// ...
}

1

也就是说:您必须在 if条件中使用“===”。

为什么?它只是不需要在与 0 比较之前将 caret_index 转换为 number

最佳答案

这不是 Visual Studio,而是您的 lint 设置。如果您的项目根目录中没有 .eslintrc.json 文件,请创建它。 Visual Studio 将读取它以查看应应用哪些规则。寻找三等号规则:

    "triple-equals": [
false,
"allow-null-check"
]

或者,如果您在规则目录下有任何引用,它可能是包含在外部文件中的规则:

"rulesDirectory" :[]

关于JavaScript 编译器在 Visual Studio 中到处都需要 '===' 而不是 '==',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38550648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com