How well do you understand JavaScript promises?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Can you spot the bug in this code because if you can't you may need to reassess your understanding of how promises work so we have this function that can throw an error 50% of the time and the key is that this is an async function then we have this other function that is going to get the result of this function that can throw and it's just going to return that result and then down here we're just going to console log the result of that function let's run this and see what it does so you can see that it resolves with a number and then finally we get this function to throw an error and we can see that it said I throw an error but we don't see the I CAU the error and the reason for this is because we're not resolving the promise before we return it therefore we can never catch the error so we need to make this an async function and we need to return a wait so you can see now that when the function throws an error we do actually catch the error
Info
Channel: TomDoesTech
Views: 12,893
Rating: undefined out of 5
Keywords:
Id: GPg1fsXl-DY
Channel Id: undefined
Length: 0min 52sec (52 seconds)
Published: Sun Feb 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.