null与undefined的简单区别

当声明的变量还未被初始化时,访问则返回undefined,而null表示尚未存在的对象

console.log(type null);//object,可以理解为对象占位符
console.log(type undefined);//undefined
console.log(null==undefined);//true,ECMAScript认为undefined是null派生出来的,所以相等
console.log(null===undefined);//false
console.log(type null ==type undefined);//false,因为类型不同

猜你喜欢

转载自blog.csdn.net/weixin_38323736/article/details/79645118