In this article we will learn the concept of callback function in JavaScript.

Callback function in JavaScript

In this article we will try to understand the concept of
callback function in JavaScript. The callback approach is one of the examples
of function oriented programming. The concept of callback is , The function
will call another function when it will finish it’s execution. The callback
function is very necessary in various scenarios. For example, we want to show
one text after loading of page or finishing of certain animation, in those scenario
we can implement callback function.

Example of simple callback

In this example we will try to implement one simple callback
function. We know that in JavaScript ,function is one type of object and we can
send function as function argument. Here is one example

Before calling to callback function we can check it’s type. It is always a best practice to check the type of argument. If the
callback argument is not function type then it will show error message in
console.