
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is setTimeout() Method in javascript?
setTimeout()
This is one of the many timing events. The window object allows the execution of code at specified time intervals. This object has provided SetTimeout() to execute a function after a certain amount of time. It takes two parameters as arguments. One is the function and the other is the time that specifies the interval after which the function should be executed.
syntax
window.setTimeout(function, milliseconds);
Example-1
In the following example, the time passed to the setTimeout() function is 2 seconds. Therefore the function will be executed after two secs and display the output as shown.
<html> <body> <p>wait 2 seconds.</p> <script> setTimeout(function(){ document.write("Tutorix is the best e-learning platform"); }, 2000); </script> </body> </html>
Output
wait 2 seconds Tutorix is the best e-learning platform
Example-2
In the following example, the time passed to the setTimeout() function is 3 seconds. Therefore the function will be executed after three secs and display the output as shown.
<html> <body> <p id = "time"></p> <script> setTimeout(function(){ document.getElementById("time").innerHTML = "Tutorix is the product of Tutorialspoint"; }, 3000); </script> </body> </html>
Output
Tutorix is the product of Tutorialspoint.
- Related Questions & Answers
- What is the difference between setTimeout() and setInterval() in JavaScript?
- How to use setTimeout() function in JavaScript?
- What is Number.toExponential() method in JavaScript?
- What is onerror() Method in JavaScript?
- What is setInterval() method in JavaScript?
- What is a constructor method in JavaScript?
- What is a JavaScript call() Method?
- What is a JavaScript apply() Method?
- What is importance of startsWith() method in JavaScript?
- What is the usage of join() method in JavaScript?
- What is the role of filter() method in JavaScript?
- What is the usage of every() method in JavaScript?
- What is the usage of fill() method in JavaScript?
- What is the usage of copyWithin() method in JavaScript?
- What is the usage of some() method in JavaScript?
Advertisements