JavaScript setTimeout: Delay Function Execution - Guide & Examples
setTimeout is a JavaScript function that allows you to schedule a function to run after a specified amount of time has passed. The syntax for setTimeout is as follows:
setTimeout(function, delay);
The first argument is the function that you want to run after the specified delay, and the second argument is the amount of time, in milliseconds, that you want to wait before running the function.
For example, the following code will log 'Hello, world!' to the console after a delay of 1000 milliseconds (1 second):
setTimeout(function() {
console.log('Hello, world!');
}, 1000);
You can also pass additional arguments to the function using the setTimeout method:
setTimeout(function(arg1, arg2) {
console.log(arg1 + ' ' + arg2);
}, 1000, 'Hello,', 'world!');
This will log 'Hello, world!' to the console after a delay of 1000 milliseconds, using the two arguments passed to the function.
原文地址: https://www.cveoy.top/t/topic/opgF 著作权归作者所有。请勿转载和采集!