CallBack Functions In Javascript

CallBack Functions In Javascript

Callback Function

  • JavaScript is a Synchronous single thread language. This basically means it can execute only one instruction at a time and the program flow is from top to bottom.
  • But however, JavaScript can be written in such a way that it becomes Asynchronous in nature.
  • Functions in JavaScript are called first-class citizens, which implies functions are nothing but objects and hence they can be passed to another function using a variable
  • Callback Functions are those functions in which functions are passed are parameters and are invoked inside that function
  • Inherently JavaScript Callback functions do not make the program asynchronous, but when they are passed to special functions like event handlers then JavaScript becomes Asynchronous
  • The Snippet below represents a callback function.

callback_function.jpg