javaScript promises explained tutorial
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about asynchronous code and when they want a simple first explanation of promises.
Recommended by 3 people across 3 different months, 2017 to 2018.
What it is
A 13-minute beginner tutorial by techsith explaining how JavaScript promises work, with a real-world example and a focus on avoiding callback hell. It covers creating promises, chaining with then, and combining them with Promise.all.
What people said
Recommends Lewis Thomas · 2017-01 · Stack Overflow · on “alexa Steam custom skill api integration”
I have managed to solve my problem by using javascript promises. I'm completely new to promises so took some trial and error but have managed to get it to work. here is the simplest video [this video] i could find to explain the concept, it definately helped me understand how to rearrange my code. If you wish to do two API calls in an Alexa skill, using the data from the first api call to construct and inform the second call, you will need to use promises to do them sequentially. it took the code from the isOnline() and testGet() functions and moved them into a promise, which allowed me to complete 1 api call (the original call to get friends list info) before executing the second call (the secon
Recommends JGFMK · 2017-08 · Stack Overflow · on “asynchronous typescript to synchronous typescript”
@vivek [this video] - Promise all example appears around 12:14.. .There's a JsFiddle for part of the code a bit before that.. [LINK]
Recommends Arthur Tarasov · 2018-07 · Stack Overflow · on “How to load up CSS files using Javascript?”
In a modern browser you can use promise like this. Create a loader function with a promise in it: function LoadCSS( cssURL ) { // 'cssURL' is the stylesheet's URL, i.e. /css/styles.css return new Promise( function( resolve, reject ) { var link = document.createElement( 'link' ); link.rel = 'stylesheet'; link.href = cssURL; document.head.appendChild( link ); link.onload = function() { resolve(); console.log( 'CSS has loaded!' ); }; } ); } Then obviously you want something done after the CSS has loaded. You can call the function that needs to run after CSS has loaded like this: LoadCSS( 'css/styles.css' ).then( function() { console.log( 'Another function is triggered after CSS had been loaded.
Cites AIon · 2017-10 · Stack Overflow · on “Function returns undefined while console.log the expected value (javascript/nodejs)”
what you are getting here is expected. `googleMapsClient.geocode` is running asynchronously - so as soon as you hit `googleMapsClient.geocode` function - you just skip to the end of `exports.geocodeAddress` - and so the return value for `exports.geocodeAddress` is undefined. To solve this you have 2 options. If `googleMapsClient.geocode` returns a promise you just do: `return googleMapsClient.geocode .. ` if not - you need to create your own promise object inside that function and return that, and resolve it in callback. More about promises here: [this video]