Note: This article is focused on client-side JavaScript in the browser environment. In this article, you will learn about the event loop, the original way of dealing with asynchronous behavior through callbacks, the updated ECMAScript 2015 addition of promises, and the modern practice of using async/ await. This is useful because it allows the user to continue using the browser normally while the asynchronous operations are being processed.Īs a JavaScript developer, you need to know how to work with asynchronous Web APIs and handle the response or error of those operations. In order to prevent blocking behavior, the browser environment has many Web APIs that JavaScript can access that are asynchronous, meaning they can run in parallel with other operations instead of sequentially. If API calls were performed in a synchronous manner, the browser would not be able to handle any user input, like scrolling or clicking a button, until that operation completes. However, an action like requesting data from an API can take an indeterminate amount of time, depending on the size of data being requested, the speed of the network connection, and other factors. Since JavaScript is a single-threaded programming language with a synchronous execution model that proccesses one operation after another, it can only process one statement at a time. To handle these operations in JavaScript, a developer must use asynchronous programming techniques. But now that web applications have become more interactive and dynamic, it has become increasingly necessary to do intensive operations like make external network requests to retrieve API data. In the early days of the internet, websites often consisted of static data in an HTML page. This article was originally written for DigitalOcean.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |