-
Notifications
You must be signed in to change notification settings - Fork 139
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
JS 作用域链相关问题 #25
Comments
下面是我的理解,有什么问题还望指正,解法采用和 #23 一样的解法。
|
作用域链是定死的,函数引用的变量在哪里定义,引用的就是哪里的变量. fn3()在全局定义,所以引用的是全局的a fn2在fn内部定义,fn内部有一个a了,所以fn2操作的都是fn内的a, 第一个undefined是因为var声明变量提前所以是undefined. |
|
最终输出为:
答案分析:
1、作用域在全局,调用全局变量 a,但由于函数内部变量重新声明,且根据变量声明提前但赋值不会提前,所以输出 undefined |
变量声明提前 |
最近讲到作用域链,再来一发作用域链的题目。下面代码输出什么? 为什么?
The text was updated successfully, but these errors were encountered: