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

循环/闭包/setTimeout/Promise 综合 #30

Open
Panda-HJN opened this issue Feb 24, 2017 · 2 comments
Open

循环/闭包/setTimeout/Promise 综合 #30

Panda-HJN opened this issue Feb 24, 2017 · 2 comments

Comments

@Panda-HJN
Copy link

Panda-HJN commented Feb 24, 2017

  1. 控制台显示内容为?
for (var i = 0; i < 5; i++) {
  console.log(i);
}
  1. 控制台显示内容为?
for (var i = 0; i < 5; i++) {
  setTimeout(function() {
    console.log(i);
  }, 1000 * i);
}
  1. 控制台显示内容为?
for (var i = 0; i < 5; i++) {
  (function(i) {
    setTimeout(function() {
      console.log(i);
    }, i * 1000);
  })(i);
}
  1. 控制台显示内容为?
for (var i = 0; i < 5; i++) {
  (function() {
    setTimeout(function() {
      console.log(i);
    }, i * 1000);
  })(i);
}
  1. 控制台显示内容为?
for (var i = 0; i < 5; i++) {
  setTimeout((function(i) {
    console.log(i);
  })(i), i * 1000);
}
  1. 控制台显示内容为?
setTimeout(function() {
  console.log(1)
}, 0);
new Promise(function executor(resolve) {
  console.log(2);
  for( var i=0 ; i<10000 ; i++ ) {
    i == 9999 && resolve();
  }
  console.log(3);
}).then(function() {
  console.log(4);
});
console.log(5);

知乎上看到的文章,六道题循序渐进的考察了很多东西.

做完了感觉有用就去原作者处点个赞吧.
作者:Liril

@shineSnow
Copy link

这几题主要考察了闭包还有js异步的知识,贴一下关于闭包的,https://www.zhihu.com/question/33468703

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
@shineSnow @Panda-HJN and others