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

变量未定义、变量未初始化 #25

Open
Kelichao opened this issue Nov 18, 2016 · 0 comments
Open

变量未定义、变量未初始化 #25

Kelichao opened this issue Nov 18, 2016 · 0 comments

Comments

@Kelichao
Copy link
Owner

Kelichao commented Nov 18, 2016

初始化,类型注意点

  • 在初始化变量的时候记得给予对应类型,可以判断变量是不是未定义
var name = null;
var job;
typeof name; //object
typeof age;// undefined
typeof job;// undefined
  • 在es6中用let声明变量的方式会报错
typeof e;// ReferhceError
let e;

Null注意点

null表示一个空对象指针,所以用typeof检测null时返回"object",此外null === undefined总是返回true
所以没有必要把变量的值显式的设置为undefined

@Kelichao Kelichao changed the title JS基本概念总结 变量未定义、变量未初始化 Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant