filmov
tv
JavaScript Callbacks vs Promises vs Async/Await
Показать описание
In this video i will explain the difference between using Callbacks, Promises and Async/Await in JavaScript. We will go through an example that shows how the same code can be written in 3 different ways.
Many people have a wrong understanding of this topic. JavaScript is always synchronous and single-threaded. It is only asynchronous in such a way that it can make for example Ajax Calls which run in the background and do not interrupt other parts of the code from executing. This mostly happens during server requests while waiting for data.
Describing JavaScript as asynchronous is perhaps misleading. It's more accurate to say that JavaScript is synchronous and single-threaded with various callback mechanisms. Single-threaded and Synchronous means one at a time i.e. one line of code is being executed at a time in order the code appears. JS has Callback functions whose purpose is to allow JS to behave asynchronously so further parts of JS can run while waiting for a JS function that has been executed (for example a GET call) to return a response, JS will continue to run until the browser has an answer at that point the event loop aka the(browser) will execute the JS code that calls the callback function.
This video should give you an overview of the main differences between JavaScript Callbacks vs Promises vs Async/Await.
Disclaimer:
All videos are for educational purposes and use them wisely. Any video might have inaccurate or outdated information. I give my best to research every topic thoroughly but please be aware that videos can contain mistakes.
Many people have a wrong understanding of this topic. JavaScript is always synchronous and single-threaded. It is only asynchronous in such a way that it can make for example Ajax Calls which run in the background and do not interrupt other parts of the code from executing. This mostly happens during server requests while waiting for data.
Describing JavaScript as asynchronous is perhaps misleading. It's more accurate to say that JavaScript is synchronous and single-threaded with various callback mechanisms. Single-threaded and Synchronous means one at a time i.e. one line of code is being executed at a time in order the code appears. JS has Callback functions whose purpose is to allow JS to behave asynchronously so further parts of JS can run while waiting for a JS function that has been executed (for example a GET call) to return a response, JS will continue to run until the browser has an answer at that point the event loop aka the(browser) will execute the JS code that calls the callback function.
This video should give you an overview of the main differences between JavaScript Callbacks vs Promises vs Async/Await.
Disclaimer:
All videos are for educational purposes and use them wisely. Any video might have inaccurate or outdated information. I give my best to research every topic thoroughly but please be aware that videos can contain mistakes.
Комментарии