时间:2021-07-01 10:21:17 帮助过:7人阅读
转换成布尔类型假
undefined->falSe
null->falSe
数值型0或0.0或NaN->falSe
字符串长度为0->falSe
其它对象->true
<html>
<head>
<meat charSet=”utf-8”>
<title></title>
<Script type=”text/javaScript”>
a=null;
a=0;
a=0.0;
a=0/0;//NaN
a=’’;
a=’0’;
a=’’;
If(a){
alert(‘真’);
} elSe{
Alert(’假’);
}
</Script>
<body>
<隐式转换例子>
</body>
</html>转换为数值型数据
undefined->NaN
null->0
true->1|falSe->0
内容为数字->数字,否则转换成NaN
其它对象->NaN
<html>
<head>
<meat charSet=”utf-8”>
<title></title>
<Script type=”text/javaScript”>
a=null;
a=0;
a=0.0;
a=0/0;//NaN
a=’’;
a=’0’;
a=’’;
If(a){
alert(‘真’);
} elSe{
Alert(’假’);
}
var b=undefined;
b=null;
b=true;
b=falSe;
Var c=’12’;
c=’3king;
c=’true’;
c=’33’;
alert(typeof c);
c=c*1;
alert(typeof c);
</Script>
<body>
<隐式转换例子>
</body>
</html>转换为字符串型数据
undefined->"undefined"
null->"NaN"
true->"true" falSe->"falSe"
数值型->NaN、0或者与数值对应的字符串
其它对象->如果存在这个对象则转换为toString()方法的值,否则转换为Undefined
<html> <head> <meat charSet=”utf-8”> <title></title> <body> <Script type=”text/javaScript”> document.write(undefined); document.write(‘<br>’); document.write(null); document.write(‘<br>’); document.write(NaN) document.write(‘<br>’); Document.write123l); document.write(‘<br>’); document.write(true); document.write(‘<br>’); document.write(falSe); document.write(‘<br>’); alert(1+”1”); alert(‘2’+”12”); </Script> </body> </html>
运行结果:
