欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
Undefined 与 Null 的区别
 
Undefined 与 null 的值相等,但类型不相等:
 
typeof undefined              // undefined
 
typeof null                   // object
 
null === undefined            // false
 
null == undefined             // true
 
原始数据
 
原始数据值是一种没有额外属性和方法的单一简单数据值。
 
typeof 运算符可返回以下原始类型之一:
 
string
 
number
 
boolean
 
undefined
 
实例
 
typeof "Bill"              // 返回 "string"
 
typeof 3.14                // 返回 "number"
 
typeof true                // 返回 "boolean"
 
typeof false               // 返回 "boolean"
 
typeof x                   // 返回 "undefined" (假如 x 没有值)
 
复杂数据
 
typeof 运算符可返回以下两种类型之一:
 
function
 
object
 
typeof 运算符把对象、数组或 null 返回 object。
 
typeof 运算符不会把函数返回 object。
 
实例
 
typeof {name:'Bill', age:62} // 返回 "object"
 
typeof [1,2,3,4]             // 返回 "object" (并非 "array",参见下面的注释)
 
typeof null                  // 返回 "object"
 
typeof function myFunc(){}   // 返回 "function"
 
typeof 运算符把数组返回为 "object",因为在 JavaScript 中数组即对象。

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64659.shtml