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

let和const不会变量提升 #5

Open
cloudy-rain opened this issue May 22, 2022 · 1 comment
Open

let和const不会变量提升 #5

cloudy-rain opened this issue May 22, 2022 · 1 comment

Comments

@cloudy-rain
Copy link

https://github.com/WindrunnerMax/EveryDay/blob/master/JavaScript/ES6%E6%96%B0%E7%89%B9%E6%80%A7.md
这里写到“var会变量提升,let与const也存在变量提升但有所不同。”
但是参考 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/let#%E6%8F%8F%E8%BF%B0
其实是不会提升的

@WindrunnerMax
Copy link
Owner

建议你去阅读英文原文,关于你这块,MDN的描述是

The other difference between var and let is that the latter is initialized to a value only when a parser evaluates it (see below).

他并没有对于变量提升的相关描述,如果你纠结于这个问题,不如去阅读 https://stackoverflow.com/questions/31219420/are-variables-declared-with-let-or-const-hoisted 的相关讨论

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

2 participants