Promises , async and await

Run Settings
LanguageJavaScript
Language Version
Run Command
READ THE COMMENTS FOR BETTER UNDERSTANING REVEAL THIS FIRST /* //The fancy callbacks function pranav(cb){ setTimeout(function() { cb("Logged this just by using callbacks"); },1000) } function logIt(data) { console.log(data) } pranav(logIt) */ SECOND REVEAL /* // 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) } pranav().then(logIt); */ THIRD REVEAL /* //the use case of async and await just for sake of writing clean code, intead of the above thing //for the sake of writing better code using async and await rather than .then(function() {}); function pranav() { return new Promise(function(resolve) { setTimeout(function() { resolve("this returns by the promise and by using async & await"); },1000) }) } async function main() { let value = await pranav(); console.log(value); } main(); // the above code is the same as the below code but again clean and good to use , more meaningful. // function main() { // pranav().then(function logIt(data) { // console.log(data) // }); // } */
Editor Settings
Theme
Key bindings
Full width
Lines