Null和Undefined是JavaScript里面的两种数据类型。

Undefined is a variable that has been declared but not assigned a value.

null to any variable which basically means it’s blank.

explicitly empty.

JavaScript Null 和 Undefined ?
JavaScript Null 和 Undefined ?

Null and Undefined

null. That must be done by you in your code.

Let’s get some more info on these.

JavaScript Null 和 Undefined ?
JavaScript Null 和 Undefined ?

Typeof null and undefined

undefined.

Comparison Using Abstract and Strict Equality

false.

JavaScript Null 和 Undefined ?
JavaScript Null 和 Undefined ?

Comparison between null and undefined

true.

So JavaScript does consider these to be relatively equal since they both represent an empty value.

JavaScript Null 和 Undefined ?
JavaScript Null 和 Undefined ?

undefined, you can check for abstract equality and compare it to either null or undefined. Both will return the same result.

 

 

转载自:https://levelup.gitconnected.com/javascript-null-vs-undefined-2acda986f79f

 

相关文章: