eqeqeq
需要使用 ===
和 !==
一些该规则报告的问题可以通过 --fix 命令行选项 自动修复
使用类型安全的相等运算符 ===
和 !==
而不是它们的常规对应项 ==
和 !=
被认为是一种很好的做法。
原因是 ==
和 !=
在相当晦涩的 抽象等式比较算法 之后进行类型强制。例如,以下语句都被视为 true
:
[] == false
[] == ![]
3 == "03"
A30sQOstvpkCia6E3ql9lvz94Wd2i+a+bcu4bmrsOp9seDTXMbyTCkkMM6NcDllSjgmxThEx5UcwdPEof9jARDyagdiSnWDH3inZEl8sFDJ7qXvuX7VXkPzliatqqU+fd+SVUhDE3CXNaT4L/4OFoCutHDMzepx4UaCwWZUSirA=
规则详情
48mGbweHCSa5qla5J3BHDErvOwVZWB/E0332Jbyi0u82CckcOCTy/WUDUtzFZrIVQfR51S1JQMvooJ77WcrXbA==
jvkUkhkS7HSb+ijdsHFfDvzpmX56pYNowDKn6tOSVTUtqrcHLX+N0YnSJhNxvgWE
/*eslint eqeqeq: "error"*/
if (x == 42) { }
if ("" == text) { }
if (obj.getStuff() != undefined) { }
BcBcZJ9SM12xtzyUI0srkVcSpwqZsFF7+FL/eLc1wtpGUGeNJJMKCgnfW0qd7Jbb3Yr6BRJ8BmlvSv3WIWzZtMB0ku5cLkfLx5aZJINg2NaXHlL48TG8FBicpm8nFD59180bvJF5Iu+1Qr0uO3HOxIQTly266+4bEga8bQEGvQ61IXLfl9pT6MhV89rvXwaZhAsXZ9V8KH1gycWtLipCJDPYoyLGebPhR4IN6FAPL5bJLJVYIpyVQ/8yFa5LrbX6ZnHeLFoE9EAYVONZxgtQCG2IoG/nphZ/GFSEYJKgWcSjiY4W63CqYN/rKidn0uqD
选项
always
tP2ODelTd1QnFGkJ+6Up91kVOFnNqm59PdZxaJZfU2kYQY/Rm7+MV82J27VEt0uEaU0d2sA+Sb0Bp4TVlF2TiwTFuRjxlZPdIopRmJ71cVN98BSIeujktiNfZvlBRP7oNRrMhUWfhbnNMxLYeuo/sNnOZ+OKj8+NtAJgIeTdDWc0ey58hmDIToixpiq+qgbiIyS72zk1V+n6v3s2Np6IeeJ2PgvdY7NuNyNFfpXrzxOVxplTvIf/Ryj3qYHsJjl+
tP2ODelTd1QnFGkJ+6Up9xjFuk82cfLInd3Ke3UlganZjMDeRbK4qKtWSUfO5XsdfZngUwuOFTdLy4X2YGzdLA==
/*eslint eqeqeq: ["error", "always"]*/
a == b
foo == true
bananas != 1
value == undefined
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null
tP2ODelTd1QnFGkJ+6Up916pCXQL4q06d4bpShjthJ8t4ixK4k/wWtTfFCch/lhnYgU5xXkCI1XFV3h9guyucQ==
/*eslint eqeqeq: ["error", "always"]*/
a === b
foo === true
bananas !== 1
value === undefined
typeof foo === 'undefined'
'hello' !== 'world'
0 === 0
true === true
foo === null
5uvbNcrNfdvaEiB2ffFwf4Ds91pQUg6s2yPiA6uS1f74ChW4/q2GbTTy3x8KpwXC21CxzHDN0u0ciAMfYj0DbW9Mc1r2NrbwWoaRpewl7zLEuDzUmmUnIjecMnDyswPm
- PXdxZXXotakdO8CkqGXfxbHZ3ShBzQsHNBMV3d21ZgpyuDk5fUJt696oy/TLCK4PMamWRjYED0EE65l9den5XOEzc3B77QyK74ul5NkSFTUOz3T4EUtBgExRQDL6PdbrUvpz2WypDzam2QxEyKxqHLWh/7npTAbdw7R7xd2SugWaDxovSQuL7lhkiFcMeekz7J0abs4Sd46Y68FYPtOLMqzI/pF+Tps1dB2pcXowMYoHnL1Rx9NFAxHqVhKXHmzRo6Nn723LvHmfC/KnqtJ5ulFeuwSlQm+GvHfFScSazHUV1kSlxFB5u+Fzll764dKw84dtZorqJaHuwpt6DGHlskd/76B4sk/Ltazq/WrjkrDUAh5UgNk9nAZuOWxPJMYmncmZhuNX/FC/1fXmdTvVgUW4W2DnPc7kfOl+KweWbWt/kueDbZDgJ2jNL6PbDaTvOnUsq1gCg+JD4TZI7ka3KFUC8p/81+d+g/WdpSRZPWs=
smart
eBBHycZl/PEHYWwF8g0uTVB+84wgv9xE+bwfJ79waO5Fl8SLph+zgIoM0bZ9Lxqsh0ejbbmS8VKut9R//47JqSzks4mCKJmUI4T0x37om5egwT0fmKLcRlnhMB2fw0niYG44EjWenpP5y6v0KDXGag==
- UEwYU7TaP7R/F9jlmYINXFnwJLg5+SXwZFe1wQgJYyjifH74GvD05mWXakAwjS2kmMjp8EikWXgEZTmZTtj69QZZnY0jRhhbNUNXeZnlZsvEekKTVOw51mTmn67RS5f0GTH+4izbyiFHt6bhxV1qMOdwHt79dFCRsLhEGmTIYS0=
eBBHycZl/PEHYWwF8g0uTfwEx+4AWaDiKaoQQysTJwUTC7CDCGithgpf9LXRMder4E3Fkig+BnEu3GEBgyuybA==
/*eslint eqeqeq: ["error", "smart"]*/
// comparing two variables requires ===
a == b
// only one side is a literal
foo == true
bananas != 1
// comparing to undefined requires ===
value == undefined
eBBHycZl/PEHYWwF8g0uTVejMeFOiYj2fheCPs8shEevk4zKr1D/hiNUJjId89zjteW0jg/HMx6R1glJz5tNdg==
/*eslint eqeqeq: ["error", "smart"]*/
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null
allow-null
JLlhSYlTFit/B7Ajv2RIiSbiVNvqnPk238qsHdSofPJ10fWD/T4Z/aL/84aIdZSRrvCsKGAa3REkAENfG4X5RUXoGmKjt1vmGlhENU4gu7/m21LdmFnKeD9fRFstZ2YdpagwbX06ZHjqpKPa+E6Rd9G5W6J+cQ3+QZ7wGIqBI+iWnwPX85FQB7qRGGZ6lFXNREUEYkRrEgBD/NWI6l3Th5CnAGtcwWnqGtsTQl3sL0EdprNfS60O13s+niHgcxRX5UNqkQGPsMMTZzTeERrOB7TKtQSWNmnqqQri/5ZpmrhSvnac0Aakiuc0xMR44Ou8LtPxbbpxZmniIJPesQFwX2ZkSIwrBu3jpl0iqdV09Pw=
["error", "always", {"null": "ignore"}]
何时不使用
f3XHMeVhl6UnvO889vwUbSmM4sk7KP59/J/Nq8mh61F7+q6Y0zyYtyOrLgsZE+wlNp+GLz8Wow1/VKovkULPmguNaFCEokG4I5lXExKedv2MfSzwSRs92WQN+WSusUZE