The js closure implements counting in seconds


Here is a tip for counting by seconds using the javascript closure. The code is as follows:

var i =1;
for(i; i<10; i++){
  (function(num){
   setTimeout(function(){
     console.log(num);
     }, num*1000);
   })(i);
}

The focus is on the scope of closures.

That’s all for this article, I hope you enjoy it.