undefined 是指变量未赋任何类型的值
null 变量是一个空的 object
null 变量是一个空的 object
解决方案 »
- js实例
- 冒号:是什么运算符?
- 请帮忙改一段JS代码,加入Cookie操作控制层的显示状态
- 把iframe嵌入.js文件中,代码该如何写?只有60分了,准备加!
- js中如果cookie大于4k后用document.cookie不能读出,但服务器端用request.cookies能行!!为什么?
- 【Firing fox,I crashed: How to write HTML to iframe using JS】
- 如何通过html页面中的按钮来控制网页中的flash,使其读取不同xml文件中的所存储的图片路径
- 在php中获取js克隆表的数据
- 我是菜鸟,请帮忙!!!
- 100分求一个比较一维数组中数字大小的JAVASCRIPT程序!UP有分!
- 能否禁止脚本的执行?
- 如果用javascript如何把长的数字用逗号隔开显示
The null data type has only one value in JScript: null. The null keyword cannot be used as the name of a function or variable.A variable that contains null contains "no value" or "no object." In other words, it holds no valid number, string, Boolean, array, or object. You can erase the contents of a variable (without deleting the variable) by assigning it the null value.Notice that in JScript, null is not the same as 0 (as it is in C and C++). Also note that the typeof operator in JScript will report null values as being of type Object, not of type null. This potentially confusing behavior is for backwards compatibility.Undefined Data Type
The undefined value is returned when you use: an object property that does not exist,
a variable that has been declared, but has never had a value assigned to it.
Notice that you cannot test to see if a variable exists by comparing it to undefined, although you can check if its type is "undefined". In the following code example, assume that the programmer is trying to test if the variable x has been declared:// This method will not work
if (x == undefined)
// do something// This method also won't work - you must check for
// the string "undefined"
if (typeof(x) == undefined)
// do something// This method will work
if (typeof(x) == "undefined")
// do something
Consider comparing the undefined value to null.someObject.prop == null;
This comparison is true, if the property someObject.prop contains the value null,
if the property someObject.prop does not exist.
To check if an object property exists, you can use the new in operator:if ("prop" in someObject)
// someObject has the property 'prop'