22、比较运算符

yu
yu
2024-10-04 / 0 评论 / 4 阅读 / 正在检测是否收录...
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        console.log(3 > 5)
        console.log(3 >= 3)
        console.log(2 == 2)
        // 比较运算符有隐式转换 把字符型的‘2’转换成数字类型的‘2’ 双等号只判断值
        console.log(2 == '2')
        console.log(undefined == null)//true
        console.log(undefined === null)//false
        // 还判断数据类型
        // 常用三等 ===
        console.log(2 === '2')
        console.log(NaN === NaN) //NaN不等于任何人,包括他自己
        console.log(2 !== '2')//true
        console.log(2 != '2')//false
        console.log('-------------------')
        console.log('a' < 'b')//true
        console.log('aa' < 'ab')//true
    </script>
</body>
</html>
0

评论 (0)

取消