美文网首页
null==undefined

null==undefined

作者: 胡悦同学 | 来源:发表于2020-04-17 21:11 被阅读0次

null和undefined有什么区别?为什么相等?

// 关系判断
console.log(null==undefined);// true
console.log(null===undefined);// false

// typeof类型判断
console.log(typeof null);// object
console.log(typeof undefined);// undefined

// 转为number类型
console.log(Number(null));// 0
console.log(Number(undefined));// NaN

1.null空对象指针,表示此处不应该有值,是原型链的终点,常用来占位,定义某个值为空
2.undefined表示此处应该有值,但未被定义
3.undefined和null都表示“空”的意思
4.undefined派生自null

相关文章

网友评论

      本文标题:null==undefined

      本文链接:https://www.haomeiwen.com/subject/bmfuvhtx.html