The difference between undefined and null

1. different meanings

  undefined: when using var to declare variables but did not indicate it to be initialized, the value of this variable is undefined

  null: null is a pointer to the object, it expressed its readiness to hold objects, not really saving value of the object,

  If you define a variable to hold the object to prepare in the future, should the variable is initialized to null.

2. Different types

  Uninitialized defined value is detected typeof "undefined" (character string),

  And null values ​​are detected typeof "object" (String)

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

3. When the value is converted to a different

 

Guess you like

Origin www.cnblogs.com/nylgwn/p/11125604.html