javascript - Return from a promise then() - Stack Overflow

PHOTO EMBED

Wed Jul 14 2021 13:04:39 GMT+0000 (UTC)

Saved by @joannpav #javascript

function justTesting(input) {
    return new Promise(function(resolve, reject) {
        // some async operation here
        setTimeout(function() {
            // resolve the promise with some value
            resolve(input + 10);
        }, 500);
    });
}

justTesting(29).then(function(val) {
   // you access the value from the promise here
   log(val);
});

// display output in snippet
function log(x) {
    document.write(x);
}
content_copyCOPY

https://stackoverflow.com/questions/34094806/return-from-a-promise-then