js中null和undefined区别

版权声明: https://blog.csdn.net/bsfz_2018/article/details/81704560

null是空对象引用,引用指向为空
undefined是只定义了引用

typeof null:”object”
typeof undefined : “undefined”

null == undefined true
null === undefined false :值相同,但类型不同

均可以用null或者undefined清空属性

var person = null; // 值为 null(空), 但类型为对象
var person = undefined; // 值为 undefined, 类型为 undefined

猜你喜欢

转载自blog.csdn.net/bsfz_2018/article/details/81704560