- 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
What are callback functions in JavaScript?
When a function is passed to another function, it is called a callback function. It goes over this function than to call a passed function.
Example
You can try to run the following code to learn how to work with callback functions −
<html> <head> <script> var callback = function(myCallback) { setTimeout(function() { myCallback(); }, 5000); }; document.write("First is displayed"); document.write("<br>Second is displayed"); callback(function() { document.write("This is Callback function"); }); document.write("<br>Last is displayed"); </script> </head> </html>
Advertisements