<!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(Boolean(''));
console.log(Boolean(0));
console.log(Boolean(NaN));
console.log(Boolean(null));
console.log(Boolean(undefined));
console.log(Boolean('小白'));
console.log(Boolean('12'));
/* 总结:转换为布尔型使用Boolean(),在转换时,代表空,否定的值会被转换为false,如空字符串
,0,NaN,null和undefined,其余的值转换为true.
*/
</script>
</body>
</html>
转为布尔型的方法
最新推荐文章于 2024-06-16 16:36:34 发布