CallBack Function in JavaScript

Posted by

In this tutorial, you will learn about JavaScript callback functions with the help of examples.

In JavaScript, you can also pass a function as an argument to a function. This function that is passed as an argument inside of another function is called a callback function.

Example:

// function
function greet(name, callback) {
    console.log('Hi' + ' ' + name);
    callback();
}

// callback function
function callback() {
    console.log('this is callback fundtion');
}

// passing function as an argument
greet('abhishek', callback);

OutPut:

Hi abhishek
this is callback fundtion

In the above program, there are two functions. While calling the greet() function, two arguments (a string value and a function) are passed.

The callback() function is a callback function.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] CallBack Function in JavaScript […]

1
0
Would love your thoughts, please comment.x
()
x