The difference is null undefined

According to the teacher talked about as well as online bigwigs explained tidied

Null:

js keywords is null, null values ​​represent, null can be seen as a special object of value, if an object is null, indicating that the object is not a valid object.

Undefined:

The following situation will return undefined:

1. Use of an undefined variable; var i;

2. Use a variable is defined but not declared;

3. Use of an object property, but the property does not exist or is not assigned;

4. When the call function, the provider does not provide the parameters:

          function func(a){

                 console.log(a);

         }

         func();//undefined

 5) When the function does not return a value, default return undefined

         var a = func ();

         a;//undefined

 

Difference between the two:

1. not the same type:

     console.log(typeOf undefined); //undefined
     console.log(typeOf null ); //object

2. converted to different values: undefined is NaN, null 0

    console.log(Number(undefined)); //NaN
    console.log(Number(10+undefined)); //NaN
 
    console.log(Number( null )); //0
    console.log(Number(10+ null )); //10

 3.undefined===null;//false

    undefined==null;//true

 

 

Null:

js keywords is null, null values ​​represent, null can be seen as a special object of value, if an object is null, indicating that the object is not a valid object.

Undefined:

The following situation will return undefined:

1. Use of an undefined variable; var i;

2. Use a variable is defined but not declared;

3. Use of an object property, but the property does not exist or is not assigned;

4. When the call function, the provider does not provide the parameters:

          function func(a){

                 console.log(a);

         }

         func();//undefined

 5) When the function does not return a value, default return undefined

         var a = func ();

         a;//undefined

 

Difference between the two:

1. not the same type:

     console.log(typeOf undefined); //undefined
     console.log(typeOf null ); //object

2. converted to different values: undefined is NaN, null 0

    console.log(Number(undefined)); //NaN
    console.log(Number(10+undefined)); //NaN
 
    console.log(Number( null )); //0
    console.log(Number(10+ null )); //10

 3.undefined===null;//false

    undefined==null;//true

 

 

Guess you like

Origin www.cnblogs.com/mmit/p/11455065.html
Recommended