In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the differences between the two timers in javascript". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the differences between the two timers in javascript"?
Difference: the setTimeout () timer executes some code after a specified time, and the code execution stops automatically once, while the setInterval () timer repeats some code according to the specified period, and the timer does not stop automatically, you need to call clearInterval () to stop manually.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
JavaScript timers, sometimes called "timers", are used to perform certain tasks after a specified period of time, similar to the alarm clock in our lives.
In JavaScript, we can use timers to delay the execution of some code or to repeat some code at regular intervals. For example, you can use a timer to regularly update advertisements on a page or display a real-time clock, and so on.
There are two ways to set timers in JavaScript, setTimeout () and setInterval ().
SetTimeout () calls a function or evaluates an expression after the specified millisecond
Pass in three parameters
The JS code string to be executed after the function that code must call
The number of milliseconds that millisec must wait before executing the code
Lang optional generally do not write, select the script language type
SetInterval () calls the function or evaluates the expression according to the specified period. Method keeps calling the function until the clearInterval call or the window closes
Pass in three parameters
The function or code string that code must call or execute
The interval between millisec must execute periodically or call code
Lang is optional, half of which is left empty. Select language type.
The differences between setTimeout () and setInterval () are as follows:
The method states that setTimeout () executes some code after the specified time (in milliseconds). The code will only execute setInterval () once to repeat the execution of some code according to the specified period (in milliseconds), and the timer will not stop automatically unless the clearInterval () function is called to manually stop or close the browser window. Thank you for reading. This is the content of "what are the differences between the two timers in javascript?" After the study of this article, I believe that we have a deeper understanding of the difference between the two timers in javascript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.