70、转换为布尔型

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>
        // 有字符串的加法 "" + 1 结果是 "1"
        // 减法-(像大多数数学运算一样)只能用于数字,它会使空字符串 ""转换为0
        // null 经过数字转换之后变为0
        // undfined 经过数字转换之后会变成为 NaN
        console.log(Boolean('pink'))
        console.log(Boolean('')) //false
        console.log(Boolean(0))  //false
        console.log(Boolean(-1)) //true
        console.log(Boolean(undefined)) //false
        console.log(Boolean(null)) //false
        console.log(Boolean(NaN)) //false

        console.log('-------------------------------')

        if(true){
            console.log(11)
        }
    </script>
</body>
</html>
0

评论 (0)

取消