Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2021/01/28 - null是对象吗?为什么 #32

Open
lxinr opened this issue Jan 28, 2021 · 0 comments
Open

2021/01/28 - null是对象吗?为什么 #32

lxinr opened this issue Jan 28, 2021 · 0 comments
Labels

Comments

@lxinr
Copy link
Owner

lxinr commented Jan 28, 2021

null的概念

null是一种原始类型,且这种类型的唯一值只有null,当null作为值存在时,用于表示对象的值未设置,或者说把它当成一个还没有创建的对象

nullundefined的区别

一般情况而言,两者没有区别,在布尔运算中都会认为是Falsy,但在Ecma262标准中,两者的定义有着一些差别,标准定义中undefined作为值时,表示未给变量赋值时的原始值,而null在作为值时,表示的是有意缺少任何对象值的原始值,所以两者的区别可以认为是:

  • null表示是一个没有创建的对象,这也能在标准定义上勉强解释为什么typeof null == 'object'
  • undefined表示一个变量缺少了值,即未给变量赋值时的原始值
@lxinr lxinr added the JS基础 label Jan 28, 2021
@lxinr lxinr changed the title null是对象吗?为什么 null是对象吗?为什么 Jan 28, 2021
@lxinr lxinr changed the title null是对象吗?为什么 2021/01/28-null是对象吗?为什么 Jan 28, 2021
@lxinr lxinr changed the title 2021/01/28-null是对象吗?为什么 2021/01/28 - null是对象吗?为什么 Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant