JSFiddle - React, Tailwind, and code Playground

by Boban Stojanovski

JavaScript

function asyncOper1(value, callback) {
    setTimeout(function() {
        callback("One second has passed since " + value);
    }, 1000);
}

function asyncOper2(value, callback) {
    setTimeout(function() {
        callback("Two seconds were added, then " + value);
    }, 2000);
}

function asyncOper3(value, callback) {
    setTimeout(function() {
        callback("A long time (3 seconds) went by before " + value);
    }, 3000);
}

function alertResult(value) {
    alert(value);
}

// Call them all; alert the final result
asyncOper1("we started", function(strVal1) {
    asyncOper2(strVal1, function(strVal2) {
        asyncOper3(strVal2, function(strVal3) {
                alertResult(strVal3);
        });
    });
});