DEV Community

skptricks
skptricks

Posted on

Understanding Javascript Callback Function

Post Link : Understanding Javascript Callback Function

This tutorial explains basic implementation of javascript callback function and it's working in real time scenarios. Simply you can say a callback is a function that is to be executed after another function has finished executing, for that reason we called it as a ‘call back’.

Understanding Javascript Callback Function

What is Callback Functions ?
When a function simply accepts another function as an argument, this contained function is known as a callback function. callback functions is a core functional programming concept, and you can find them in most JavaScript code. Example :- setInterval

Why do we need Callbacks ?
Callbacks are a way to make sure certain code doesn’t execute until other code has already finished execution.
JavaScript Callback Functions can be used synchronously or asynchronously.

Lets see the below example and understand the execution flow of javascript.
function first(){
console.log(1);
}
function second(){
console.log(2);
}
first();
second();

Understanding Javascript Callback Function

Read more....

Top comments (0)