<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yanir</title>
    <description>The latest articles on DEV Community by Yanir (@yanir).</description>
    <link>https://dev.to/yanir</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F567008%2Fc643c9b9-0527-4f1b-ab59-b00aa7cc51a0.jpeg</url>
      <title>DEV Community: Yanir</title>
      <link>https://dev.to/yanir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yanir"/>
    <language>en</language>
    <item>
      <title>What the heck are callbacks? Promises? Async\Await? — what a MESS</title>
      <dc:creator>Yanir</dc:creator>
      <pubDate>Sat, 05 Mar 2022 17:54:43 +0000</pubDate>
      <link>https://dev.to/yanir/what-the-heck-are-callbacks-promises-asyncawait-what-a-mess-hie</link>
      <guid>https://dev.to/yanir/what-the-heck-are-callbacks-promises-asyncawait-what-a-mess-hie</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;My goal in this post series is meant to help you get a better understanding of this large concept by looking at many different perspectives and explanations. I hope you find it helpful in getting a better understanding what asynchronous is and why you need to understand it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But first, let's start from the very beginning, lets dive in (:&lt;/p&gt;

&lt;p&gt;JavaScript is a single threaded programming language. OK… Let's try again.&lt;/p&gt;

&lt;p&gt;JavaScript uses the Single Thread Runtime, which means one thing is done at a time. In other words, it can run one piece of code at a time and must finish executing it before moving on to the next.&lt;br&gt;
So how does JS handle asynchronous operations?&lt;/p&gt;

&lt;p&gt;So, the fact is JavaScript is a single threaded programming language BUT the JavaScript runtime is definitely not.&lt;br&gt;
For a clearer picture of how JS runtime works, we need to understand first what are Stack and Heap.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stack Memory:&lt;/em&gt;&lt;br&gt;
The stack is a place in computer memory where all the variables that are declared and initialized before runtime are stored.&lt;br&gt;
Uses to store static data, static data is data where the engine knows the size at compile time, in JS this includes Primitive values (string, numbers, booleans, etc…).&lt;br&gt;
Stack is much faster than the heap but also smaller and more expensive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kUYunIxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmfibka1dykubrio38kl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kUYunIxi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmfibka1dykubrio38kl.png" alt="Image description" width="880" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Memory Heap:&lt;/em&gt;&lt;br&gt;
heap is the section of computer memory where all the variables created or initialized at runtime are stored.&lt;br&gt;
It is a different place for storing data like objects/variables.&lt;br&gt;
The heap is more flexible than the stack. That's because memory space for the heap can be dynamically allocated and de-allocated as needed.&lt;/p&gt;

&lt;p&gt;Here are the two storages compared side by side for the table lovers &amp;lt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NDXssmLG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pi1bv6mdkpgmyraybz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NDXssmLG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pi1bv6mdkpgmyraybz6.png" alt="Image description" width="583" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, in conclusion, we need the memory heap as a place to store and write information and the stack help us keep track of where we are in the code so that we can run the code in order.&lt;/p&gt;

&lt;p&gt;I've learned this from some other great articles I want to mention here as well:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://felixgerschau.com/javascript-memory-management/"&gt;Javascript Memory Management&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap"&gt;what-and-where-are-the-stack-and-heap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@BenDiuguid/asynchronous-adventures-in-javascript-understanding-the-event-loop-fc6f968d5f72"&gt;asynchronous-adventures-in-javascript-understanding-the-event-loop&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope you'll find this post useful and in the next post we'll continue diving into how V8 engine works and how it helps us (:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yanir, Full-Stack developer with passion to JS&lt;br&gt;
&lt;a href="https://github.com/Yanir-R"&gt;Github &lt;/a&gt;| &lt;a href="https://www.linkedin.com/in/yanirrot/"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>asynchronous</category>
      <category>callstack</category>
      <category>heapmemoery</category>
    </item>
  </channel>
</rss>
