- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I pass a parameter to a setTimeout() callback?
To pass a parameter to setTimeout() callback, use the following syntax −
setTimeout(functionname, milliseconds, arg1, arg2, arg3...)
The following are the parameters −
- function name − The function name for the function to be executed.
- milliseconds − The number of milliseconds.
- arg1, arg2, arg3 − These are the arguments passed to the function.
Example
You can try to run the following code to pass a parameter to a setTimeout() callback
<!DOCTYPE html> <html> <body> <button onclick="timeFunction()">Submit</button> <script> function timeFunction() { setTimeout(function(){ alert("After 5 seconds!"); }, 5000); } </script> <p>Click the above button and wait for 5 seconds.</p> </body> </html>
Advertisements
To Continue Learning Please Login
Login with Google