What is the difference between null and undefined in JavaScript?

前端 未结 30 3368
夕颜
夕颜 2020-11-21 23:06

I want to know what the difference is between null and undefined in JavaScript.

30条回答
  •  梦谈多话
    2020-11-21 23:30

    Per Ryan Morr's thorough article on this subject...

    "Generally, if you need to assign a non-value to a variable or property, pass it to a function, or return it from a function, null is almost always the best option. To put it simply, JavaScript uses undefined and programmers should use null."

    See Exploring the Eternal Abyss of Null and Undefined

提交回复
热议问题