Skip to main content

eqeqeq

强制使用类型安全的相等运算符 ===!== 代替更容易出错的 ==!= 运算符。

===!== 确保比较的值不仅相同且类型相同。另一方面,==!= 在值比较之前会进行类型转换,这可能导致意外的结果。例如 5 == "5"true,而 5 === "5"false

无效:

if (a == 5) {}
if ("hello world" != input) {}

有效:

if (a === 5) {}
if ("hello world" !== input) {}

此规则没有配置选项。如果你有意针对某个特定比较使用 ==!=(例如使用 value != null 来同时匹配 nullundefined),可以在该行使用忽略指令来抑制此规则:

// deno-lint-ignore eqeqeq
if (value != null) {}

Did you find what you needed?

编辑此页面
Privacy policy