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

变量提升 #41

Open
zuopf769 opened this issue May 9, 2023 · 4 comments
Open

变量提升 #41

zuopf769 opened this issue May 9, 2023 · 4 comments

Comments

@zuopf769
Copy link

zuopf769 commented May 9, 2023

// 1.
var a = 1;
if (true) {
    console.log(a);
    var a = 2;
}
// 2.
var a = 1;
if (true) {
    console.log(a);
    let a = 2;
}
@zuopf769
Copy link
Author

zuopf769 commented May 9, 2023

1,报错

@zuopf769
Copy link
Author

zuopf769 commented May 9, 2023

var a 
a = 1;
if (true) {
    console.log(a);
    a = 2;
}

@zuopf769
Copy link
Author

zuopf769 commented May 9, 2023

应该不是提升到if作用域下 提升到函数作用域下

@zuopf769
Copy link
Author

zuopf769 commented May 9, 2023

第二题 如果if是个function,那就是undefined了

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