在javascript中,为什么null !== undefined 为真,而null == undefined 也为真?
in javascript,why null !== undefined is true,but null == undefined also is true?
console.log(undefined !== null);//true
console.log(undefined == null);//true
我无法理解为什么 undefined !==null,但我知道 undefined == null,因为语言规范 explicitly says:
If x is null and y is undefined, return true
您对第一个比较使用严格相等,对后者使用非严格。您会发现 undefined === null
是预期的 false
。
console.log(undefined !== null);//true
console.log(undefined == null);//true
我无法理解为什么 undefined !==null,但我知道 undefined == null,因为语言规范 explicitly says:
If x is null and y is undefined, return true
您对第一个比较使用严格相等,对后者使用非严格。您会发现 undefined === null
是预期的 false
。