JavaScript callback

Callbacks are fairly common in JavaScript. Continue reading to learn what they are and see an example of how they’re used.

What is a callback?

A JavaScript callback is a piece of code that is sent as an argument and executed in another section of code.

JavaScript callback examples

With functions

function getName(callback) {
    var name = 'Jordan';

function showName(name) {

getName(showName); //will show "Jordan" in an alert message