Skip to content

Instantly share code, notes, and snippets.

@lx7575000
Created March 3, 2016 15:59
Show Gist options
  • Save lx7575000/fecb59210be6dd96b431 to your computer and use it in GitHub Desktop.
Save lx7575000/fecb59210be6dd96b431 to your computer and use it in GitHub Desktop.
null 和 undefined区别

#null 和 undefined ##理论区别(然并卵) null是一个表示无的对象,当其被转为数值对象时为0。 undefined是一个表示无的原始值,转为数值时为NaN ##实际用法 null表示没有对象,即该处不应该有值。

  1. 作为函数参数,表示该函数的参数不是对象。
  2. 作为对象原型链的重点---Object.prototype = null (一个空对象)

undefined表示缺少值,即此处可以有值,但还没有定义

  1. 变量被声明了,但没有赋值时,就等于undefined。
  2. 调用函数时,应该提供的参数没有提供,该参数等于undefined。
  3. 对象没有赋值的属性,该属性的值为undefined。
  4. 函数没有返回值时,默认返回undefined。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment