<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nour Belsaadet on Medium]]></title>
        <description><![CDATA[Stories by Nour Belsaadet on Medium]]></description>
        <link>https://medium.com/@nm.belsaadet?source=rss-007160eace14------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Nour Belsaadet on Medium</title>
            <link>https://medium.com/@nm.belsaadet?source=rss-007160eace14------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:20:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nm.belsaadet/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding the mechanisms of Asynchronous JavaScript: How it works in the browser]]></title>
            <link>https://medium.com/@nm.belsaadet/understanding-the-mechanics-of-asynchronous-javascript-how-it-works-in-the-browser-63a4d3bc8f5c?source=rss-007160eace14------2</link>
            <guid isPermaLink="false">https://medium.com/p/63a4d3bc8f5c</guid>
            <dc:creator><![CDATA[Nour Belsaadet]]></dc:creator>
            <pubDate>Sun, 23 Jun 2024 20:32:58 GMT</pubDate>
            <atom:updated>2024-06-23T21:53:35.877Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is a versatile and powerful programming language primarily used for web development. It operates on a single-threaded, non-blocking, and asynchronous model, which is key to its efficiency and responsiveness.</p><p><strong>Single-Threaded ?</strong></p><p>JavaScript executes code on a single thread, meaning it can only perform one operation at a time.</p><p><strong>Non-Blocking ?</strong></p><p>Even though JavaScript is single-threaded, it keeps running other code instead of waiting for long tasks to finish.</p><p><strong>Asynchronous ?</strong></p><p>JavaScript’s asynchronous (async) nature enables it to manage numerous tasks simultaneously, a capability typically associated with multi-threaded programming languages. However, JavaScript accomplishes this using a single thread.</p><p>At first glance, these aspects of JavaScript may seem contradictory: it is single-threaded and designed to execute one task at a time, yet it can handle multiple tasks simultaneously in an asynchronous manner.</p><p>Next, you will explore how JavaScript maintains its single-threaded nature while handling asynchronous operations in the browser.</p><p>Before delving into the mechanisms, I will elucidate some fundamental concepts necessary for comprehending this process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GQzy2bxagZl0nRBRdbWkQQ.jpeg" /></figure><p><strong>Memory heap : </strong>is where the JavaScript engine stores dynamically allocated memory.<strong> </strong>When you create variables and objects in your code, they are stored in the memory heap.</p><p><strong>Call stack : </strong>is a mechanism used to track function calls during the execution of a program. It operates as a Last In, First Out (LIFO) data structure, where functions are pushed onto the stack when called and popped off when completed. This process continues until the stack is empty, indicating that the program has finished executing.</p><p><strong>WEB API’s : </strong>refer to the APIs (Application Programming Interfaces) provided by web browsers that allow JavaScript code running in the browser to interact with the browser environment and perform tasks that are not possible with just the V8 engine alone. The V8 engine is the JavaScript engine that powers browsers like Google Chrome and is responsible for executing JavaScript code.</p><p><strong>Task Queue : </strong>also known as the “Callback Queue” or “Message Queue,” is a key component of the event-driven architecture of JavaScript runtimes like web browsers. It’s where asynchronous tasks, such as callbacks from asynchronous functions or events, are queued up waiting to be executed.</p><p><strong>Event loop : </strong>is a mechanism in JavaScript that continuously checks the call stack and the task queue, transferring tasks from the queue to the stack when the stack is empty, enabling asynchronous, non-blocking operations in the browser. It ensures smooth execution of multiple tasks by allowing JavaScript to handle long-running operations without freezing the main thread.</p><p>When a browser runs JavaScript code, it follows an asynchronous programming model to handle operations that take time, such as network requests or timers. Here’s how this process works :</p><ul><li><strong>Function Call</strong>: When a function is called in JavaScript code, it is placed on the top of the call stack to be executed.</li><li><strong>Synchronous Execution</strong>: The function is executed synchronously, meaning the browser waits for the function to finish before moving on to the next function.</li><li><strong>Asynchronous Operation</strong>: If the function performs an asynchronous operation, such as an HTTP request, instead of blocking the main thread waiting for the response, the browser delegates this task to a Web API provided by the browser. This API handles the operation asynchronously in the background.</li><li><strong>Placing in the Task Queue</strong>: When the asynchronous operation is completed, a callback associated with that operation is placed in the task queue.</li><li><strong>Event Loop</strong>: Meanwhile, the JavaScript engine constantly checks if the call stack is empty. When it’s empty, it retrieves the first callback from the task queue and adds it to the call stack to be executed.</li><li><strong>Callback Execution</strong>: The callback is executed, and the process repeats for other asynchronous operations, ensuring that asynchronous code is executed in a non-blocking and efficient manner.</li></ul><p>In conclusion, the asynchronous nature of JavaScript is crucial for modern web development. By understanding how JavaScript handles asynchronous operations using the event loop and task queue, developers can create more responsive and performant web applications.</p><p>This model allows applications to perform long operations like network requests without blocking the user interface, providing a smoother and more enjoyable user experience. Furthermore, by judiciously using asynchronous operations, developers can improve overall application performance by reducing wait times and optimizing resource usage.</p><p>As a web developer, mastering the concepts of asynchronous JavaScript is therefore critical for creating more performant web applications and delivering a superior user experience.</p><p>Enjoy your reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63a4d3bc8f5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>