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 执行结果 #20

Open
MaMaFish opened this issue Mar 12, 2020 · 0 comments
Open

关于 let 执行结果 #20

MaMaFish opened this issue Mar 12, 2020 · 0 comments

Comments

@MaMaFish
Copy link
Owner

MaMaFish commented Mar 12, 2020

for(var i=0; i<10; i++){
    setTimeout(function(){
        console.log(i) // 连续打印 10 个 10
    },200)
}

将 var 换成 let

for(let i=0; i<10; i++){
    setTimeout(function(){
        console.log(i) // 依次打印 0 到 9
    },200)
}

声明自执行函数

for(let i=0; i<10; i++){
    ((j)=>{
        setTimeout(function(){
            console.log(j) // 依次打印 0 到 9
        },200)
    })(i)
}
@MaMaFish MaMaFish changed the title 第20题:关于let执行结果 关于 let 执行结果 Dec 21, 2020
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