Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 560 Bytes

bb-1.md

File metadata and controls

31 lines (25 loc) · 560 Bytes

代码片段输出什么结果

function fn1(){
  for(var i=0;i<4;i++){
    var tc=setTimeout(function(i){
      console.log(i);
      clearTimeout(tc)
    },10,i);
  }
}
function fn2(){
  for(var i=0;i<4;i++){
    var tc=setInterval(function(i,tc){
      console.log(i);
      clearInterval(tc)
    },10,i,tc);
  }
}
fn1();
fn2();

fn1()结果是 0 1 2

fn2(): 结果是 0 1 2 3......Infinite

参考资料:

题目来源