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

变量作用域,闭包一节的任务,答案错误❌ #1186

Open
shylock-wu opened this issue Jan 11, 2024 · 3 comments
Open

变量作用域,闭包一节的任务,答案错误❌ #1186

shylock-wu opened this issue Jan 11, 2024 · 3 comments

Comments

@shylock-wu
Copy link

位置

image

网站实际运行效果

image

浏览器控制台运行效果

image

结论

所以我感觉实际上sayHi函数已经被提升了,并且新的词法环境使得两个变量都是能够访问到的

@shylock-wu
Copy link
Author

贴个链接

@7ASSEL
Copy link

7ASSEL commented Mar 27, 2024

+1,我这边试了也是正常

@songhn233
Copy link
Member

@shylock-wu @7ASSEL Hello,这个实际是因为 devtool 默认在非严格模式下,详见 https://zh.javascript.info/strict-mode

image

另外,在现代前端开发工具链下,预置开发环境和构建工具基本都会默认开启严格模式。除非显式的通过 @babel/plugin-transform-strict-mode 或者一些配置来放开限制(不建议),非严格模式主要为了向前兼容 ES5 之前的一些表现。

image

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

3 participants