null and undefined

Due to the weak typing of js, it is easy to confuse null and undefined.

 

null: Indicates that there should be no value here, indicating that there is no object

1. As a parameter of the function => means that the parameter is not an object

2. As the end point of the prototype chain

Judgment method :

!exp && typeof(exp)!=undefined && exp!=0

[Normally !exp is enough, but undefined and 0 can also pass for !exp]

 

undefined: Indicates that a value is missing, there should be a value here, but it has not been defined

1. Variables without assignments

2. When the function is called, parameters that should be provided but not provided

3. Properties that are not assigned in the object

4. Functions with no return value

Judgment method:

typeof(exp)=='undefined'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325688216&siteId=291194637