gpt4 book ai didi

javascript - 预期为 '===' 而看到的是 '==' eqeqeq

转载 作者:行者123 更新时间:2023-11-30 13:45:59 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Which equals operator (== vs ===) should be used in JavaScript comparisons?

(48 个回答)


2年前关闭。



if (customer === "new") {
//run code
} else {
}

当我运行这个条件时,它运行我的代码,而实际上我在客户“customername”中有字符串值,并与不等于 ("customername" != "new") 的 sring “new”进行比较它不应该在比较时运行代码。
我发现使用 === equal 将检查类型,如果类型相同,它将传递 true 所以 == 是检查值的选项,但我在使用 == 时遇到错误.
Expected '===' and instead saw '=='  eqeqeq

最佳答案

我认为您正在使用 JSHint,“eqeqeq”是确保使用严格相等运算符的选项。

来自 here :

The JSHint eqeqeq option is used to prohibit the use of the equals operator == and the does-not-equal operator !=. This enforces the use of the strict equality operators (=== and !== instead). The strict equality operators differ from their non-strict counterparts by first comparing the type of each operand, rather than attempting to coerce them to a common type. In the following example we make use of the non-strict equality operator to check whether a value is either null or undefined

关于javascript - 预期为 '===' 而看到的是 '==' eqeqeq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59326170/

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