JS difference of the null and undefined

1.null indicates no value is defined as a null value

    alert(null == document.getElementById('notExistElement'));  //output "true"        

 This code "notExistElement" does not exist, or is defined as a null value

2.undefined indicate a lack of value, that value should be here, but has not defined

    was oValue;  

 alert(oValue == undefined); //output "true"   

3. not the same type:

    console.log(typeOf undefined);//undefined

    console.log(typeOf null);//object

4. The converted value is not the same: 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

 

 

 

Guess you like

Origin www.cnblogs.com/Focus-Study/p/Study_JS.html
Recommended