Async JS Crash Course - Callbacks, Promises, Async Await
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions from developers who are confused by async code ordering, promises and callbacks, and need a beginner-friendly walkthrough of all three styles.
Recommended by 6 people across 6 different months, 2018 to 2022.
What it is
A 24-minute Traversy Media crash course on asynchronous JavaScript. Brad Traversy walks through callbacks, promises (including Promise.all) and the async/await syntax with live code examples.
What people said
Recommends jarmod · 2018-11 · Stack Overflow · on “AWS DynamoDB parsing returned data”
Async JavaScript is challenging, not least because there are numerous ways to write async code (the mainstream options are callbacks, promises, and async/await). Here are a couple of videos that attempt to describe all three: [this video] and [LINK]
Recommends DauleDK · 2019-07 · Stack Overflow · on “i can't understand the order in which my code is executing”
To understand why you see this behaviour, you need to understand asynchronous code. Nodejs will read your instructions, and then it's done. When the find method then finishes, it calls the callback defined. Imagine the find operation was very complicated, then your create function callback would be executed first. (but the find operation would be executing meanwhile). To understand this, I can recommend the following videos. Make some coffee and tune in :) What the heck is the event loop anyway? | Philip Roberts | JSConf EU [LINK] Today most Nodejs programmers use Promises to handle async code, you can learn about this here: Promises - Part 8 of Functional Programming in JavaScript [LINK] As
Recommends SiddAjmera · 2019-10 · Stack Overflow · on “use subscribe() asynchronously”
You might want to view this video about the async JavaScript by Traversy Media [this video] to better understand what is asynchronicity in browsers. It basically means a way for the browser to keep working without having to wait for something that might take some time(like a network request of a DOM Event or a call to the setTimeout method). Now browsers are single threaded so they use something called an Event Loop to perform asynchronicity. If you're interested in understanding what event loops are, there's a great talk about Event Loops by Philip Roberts here [LINK] . Now that we're on the same page( hoping that you've watched the above videos :) ), you can basically return an Observable from
Recommends Muhammad Zeeshan · 2020-01 · Stack Overflow · on “showing a image from multiple images of a product using nodejs”
I am glad that this works for you. You can just google it out and learning from the one which you can understand better. Here is a link that you can start with: [this video] Can you please accept this answer?
Recommends ousecTic · 2020-03 · Stack Overflow · on “How to handle login with MongoDB through REST API?”
I must appreciate you accepting my answer; however I am much more concern if you understand what my answer mean. I think Authentication is quite a complicated topic. I suggest you learn about promises and using the fetch request first. Here a good tutorial to get you started => [this video]
Recommends Dusan Malusev · 2020-07 · Stack Overflow · on “How to read an object outside a PROMISE .then function”
To understand promises and callbacks you should checkout this talk Event Loop [LINK] . Javascript event loop at first runs all synchronous code, that means console.log runs before any of your promise code, that is why x is undefined , callback inside .then(...) will run after all synchronous code and after all callbacks (there is difference between callbacks and promises) You can think of promise like you have postponed something to run later. async => await is just a syntactic sugar for promises, it makes our javascript look like synchronous code but it's asynchronous. Everything that i said for promises is still valid inside async => await (they are just promises) async function asynFuncti
Cites Mihrab Miah · 2022-04 · Stack Overflow · on “TypeError: Cannot read property 'then' of undefined when using JWT token and refresh token”
As if you didn't send any code snippet, it is quite clear. But after going through your code it seems after resolving the "user" you are calling two methods createSession and generateAccessAuthToken. And as you also didn't send any code snippet of these methods I'm assuming you are having error from one of the functions. And a piece of advice: Practice best error handling patterns. It will help you in your journey. [LINK] And async js: [this video]