1、7个“坑”

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <title>JavaScript完整性检查</title>
    </head>

    <body>

        <script type="text/javascript">
            console.log('0' == false); //true
            console.log(false == 0); //true
            console.log(false == ''); //true
            console.log(false == []); //true
            console.log('' == 0); //true
            console.log('' == []); //true
            console.log(0 == []); //true
        </script>
    </body>

</html>

2、避免坑的原则

(1)如果两边有true或者false,千万不要使用==

(2)如果两边有[],''或者0,千万不要使用==

(3)最好都使用===,来避免强制转换的坑!

相关文章:

  • 2021-10-02
  • 2021-11-20
  • 2021-06-14
  • 2021-06-05
  • 2022-01-13
  • 2021-08-23
猜你喜欢
  • 2021-05-08
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案