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

第8题(2019-07-31): 请写出以下代码的输出结果 #2

Open
qappleh opened this issue Jul 31, 2019 · 1 comment
Open

第8题(2019-07-31): 请写出以下代码的输出结果 #2

qappleh opened this issue Jul 31, 2019 · 1 comment
Labels

Comments

@qappleh
Copy link
Owner

qappleh commented Jul 31, 2019

var name = 'Tom';
(function() {
    if (typeof name == 'undefined') {
        name = 'Jack';
        console.log('Goodbye ' + name);
    } else {
        console.log('Hello ' + name);
    }
})();  
@qappleh
Copy link
Owner Author

qappleh commented Aug 1, 2019

hello Tom  

解析:
1、首先在进入函数作用域当中,获取name属性
2、在当前作用域没有找到name
3、通过作用域链找到最外层,得到name属性
4、执行else的内容,得到Hello Tom

@qappleh qappleh changed the title 第八题(2019-07-31): 请写出以下代码的输出结果 第8题(2019-07-31): 请写出以下代码的输出结果 Aug 1, 2019
@qappleh qappleh added the 京东 label Aug 20, 2019
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