Why is null
被认为是object
在 JavaScript 中?
正在检查
if ( object == null )
Do something
与
if ( !object )
Do something
?
并且:
有什么区别null
and undefined
?
(name is undefined)
You: What is name
? (*)
JavaScript: name
? What's a name
? I don't know what you're talking about. You haven't ever mentioned any name
before. Are you seeing some other scripting language on the (client-)side?
name = null;
You:什么是name
?
JavaScript:我不知道。
简而言之;undefined
是不存在事物概念的地方;它没有类型,并且之前从未在该范围内被引用过;null
是已知事物存在的地方,但不知道其价值是什么。
要记住的一件事是null
从概念上讲,与false
or ""
或类似的,即使它们在类型转换后相等,即
name = false;
You:什么是name
?
JavaScript:布尔值假。
name = '';
You:什么是name
?
JavaScript:空字符串
*: name
in this context is meant as a variable which has never been defined. It could be any undefined variable, however, name is a property of just about any HTML form element. It goes way, way back and was instituted well before id. It is useful because ids must be unique but names do not have to be.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)