In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, Xiaobian will share with you what the third parameter of setTimeout is and how to use it. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you will gain something after reading this article. Let's find out together.
Let's start with a simple code:
setTimeout(function(x) { console.log(x);}, 1000, 1);
Console output 1, then can you continue to add parameters? Let's continue with the following code:
setTimeout(function(x,y) { console.log(x+y);}, 1000, 1, 2);
The console outputs 3, which is obviously the sum of the third and fourth arguments.
See here many small partners should realize, yes, the third parameter of setTimeout is the parameter to the first function of setTimeout.
By querying MDN we can see the description of the third parameter:
var timeoutID = scope.setTimeout(function[, delay, arg1, arg2, ...]); var timeoutID = scope.setTimeout(function[, delay]);var timeoutID = scope.setTimeout(code[, delay]);
Therefore, in fact, setTimeout can have countless parameters, but from the third parameter, it is an optional parameter.
All right, what problem can we solve with this feature? One of the most classic is the use of setTimeout in a for loop.
for(var i = 0; i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.