setTimeout()

Overview

Calls a function after the specified interval. For example, after a failed attempt to do something, set a timeout before you retry. The timer can be canceled by calling clearTimeout() with the timer id.

Added in version 2.1.5

Format

var timerId = setTimeout(functionToCall, interval);

Value Description Type Required
functionToCall The function that should be called when the interval expires. Function Required
interval The number of milliseconds before the function is called. Integer Required
timerId A number that can be used to clear the timer. Integer Return

Example 1

Copy
/* Add a message to the log after 10 seconds
*/
Logger.debug("10 seconds starting now...");
setTimeout(function() {
    Logger.debug("...10 seconds is up!");
}, 10000);