Skip to content

Instantly share code, notes, and snippets.

@shengoo
Last active August 29, 2015 14:00
Show Gist options
  • Save shengoo/11240979 to your computer and use it in GitHub Desktop.
Save shengoo/11240979 to your computer and use it in GitHub Desktop.
null and undefined in javascript
> var un;
> console.log(un);
undefined
> var nu = null;
> console.log(nu);
null
> typeof un
'undefined'
> typeof nu
'object'
> un == nu
true
> un === nu
false
> Number(undefined)
NaN
> Number(null)
0
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