Why is null an object and what's the difference between null and undefined?

后端 未结 22 1033
猫巷女王i
猫巷女王i 2020-11-22 02:58

Why is null considered an object in JavaScript?

Is checking

if ( object == null )
      Do something

the

22条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 03:46

    1. Undefined means a variable has been declared but it has not been assigned any value while Null can be assigned to a variable representing "no value".(Null is an assignment operator)

    2.Undefined is a type itself while Null is an object.

    3.Javascript can itself initialize any unassigned variable to undefined but it can never set value of a variable to null. This has to be done programatically.

提交回复
热议问题