<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
/*
将其他的数据类型转换为Boolean
-使用Boolean()函数
--数字--->布尔
-除了0和NaN,其余都是true
字符串---.>
除了空串,其余都是true
null和undefined都会转换为falase
对象也会转换为true
*/
var a=256;//true
a=-256;//true
a=0;//true
a=Infinity;
a=NaN;
//调用Boolean()函数来将a转换为布尔值
a=Boolean(a);
a="null";//false
a=Boolean(a);
a=undefined;
a=Boolean(a);
console.log(typeof a);
console.log(a);
</script>
</head>
<body>
</body>
</html>
使用Boolean()函数除了0和NaN其余都是true
var a=256;//true
a=-256;//true
a=0;//true
null和undefined都会转换为falase尾部的代码结果如下图