Home >Web Front-end >JS Tutorial >js closure implements counting by seconds_javascript skills
Here is a little trick to share with you. Use javascript closure to count by seconds. 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.
The above is the entire content of this article, I hope you all like it.