- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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>
- Related Articles
- Passing parameters to callback functions JavaScript
- What are functions in JavaScript?
- What are generator functions in JavaScript?
- What are immediate functions in JavaScript?
- What are Partial functions in JavaScript?
- What are JavaScript Math Functions?
- What are JavaScript Nested Functions?
- What are JavaScript Factory Functions?
- What are optional arguments in JavaScript Functions?
- What are Rest parameters in JavaScript functions?
- What are Self-Invoking Anonymous Functions in JavaScript?
- Explain the callback Promise.finally in JavaScript
- What are different ways of defining functions in JavaScript?
- What is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?
- Passing a function as a callback in JavaScript

Advertisements