JSFiddle - React, Tailwind, and code Playground

JavaScript

function return1() {
        return Promise.resolve(1);
    }

    function wait(ms) {
        return new Promise(function (resolve) {
            setTimeout(resolve, ms);
        });
    }

    function increment(val) {
        return wait(1000).then(function () {
            return val + 1;
        });
    }

    function square(val) {
        return wait(1000).then(function () {
            return val * val;
        });
    }

    var p = return1()
        .then(increment)
        .then(square); // Returns a promise that will resolve to 4 (eventually)

    p.then(function (result) {
        console.log(result);
    });