时间:2021-07-01 10:21:17 帮助过:11人阅读
<script type="text/javascript">
var myBoolean=new Boolean();
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean(0);
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean(null);
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean("");
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean(false);
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean(NaN);
document.write(myBoolean);
document.write("<br />");
</script>
运行结果:
false
false
false
false
false
false
下面的所有的代码行均会创初始值为 true 的 Boolean 对象:
代码如下:
<script type="text/javascript">
var myBoolean=new Boolean(1);
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean(true);
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean("true");
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean("false");
document.write(myBoolean);
document.write("<br />");
var myBoolean=new Boolean("Bill Gates");
document.write(myBoolean);
document.write("<br />");
</script>
运行结果:
true
true
true
true
true
关于这个初始值与java和c的都不一样,以后写前台的注意啊!