Nearby lessons
14 of 22JavaScript: setTimeout() Method
📌 What is setTimeout()?
The setTimeout() method is used to execute a function after a specified delay (in milliseconds). It is a part of JavaScript's asynchronous behavior and does not block code execution.
1️⃣ Basic Usage of setTimeout()
The function will run once after a delay of specified milliseconds.
Code Example
PREVIEW READY
2️⃣ Using Named Function with setTimeout()
You can pass a function name to setTimeout() instead of an anonymous function.
Code Example
PREVIEW READY
3️⃣ Passing Arguments to the Function
setTimeout() can pass arguments to the callback function.
Code Example
PREVIEW READY
4️⃣ Cancelling setTimeout() using clearTimeout()
You can cancel the delayed function using clearTimeout() by storing the timeout ID.
Code Example
PREVIEW READY
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!AJS - setInterval