【发布时间】:2013-03-11 23:16:26
【问题描述】:
这是我正在测试的代码 --
工作正常
document.write( 1 && undefined ); // prints undefined
document.write( 1 && 3 ); // prints 3
document.write( 1 && true ); // prints true
抛出错误
document.write( 1 && NULL ); // throws Error
为什么使用 NULL 会引发错误,即使它对 undefined 也有效
虽然我测试了 typeof NULL 并给出了 undefined 但它仍然无法正常工作。让我知道这一点。 (OOP 编程新手)
【问题讨论】:
-
@Trailcoder 你可以试试 document.write(1 && null);
-
添加它以使其工作:
var NULL = null;
标签: javascript null logical-operators