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); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter