Use case of promises

Run Settings
LanguageJavaScript
Language Version
Run Command
// my own asynchronous function function pranav(cb) { console.log("in the pranavfunction"); setTimeout(function(){ cb("This is a callback function"); },1000) } function logIt(data) { console.log(data) } pranav(logIt); //Promises //just the sintactical sugar for the callback //no need of callbacks //but works by callbacks under the hood function pranav() { return new Promise(function(resolve) { setTimeout(function() { resolve("this returns by the promise"); },1000) }) } function logIt(data) { console.log(data) } console.log("before promise") pranav().then(logIt); console.log("after promise")
Editor Settings
Theme
Key bindings
Full width
Lines