<?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: Muhammad Abbas</title>
    <description>The latest articles on DEV Community by Muhammad Abbas (@mabbasctn).</description>
    <link>https://dev.to/mabbasctn</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1062994%2F131f8303-5658-4402-9dab-e738fa6b2777.jpeg</url>
      <title>DEV Community: Muhammad Abbas</title>
      <link>https://dev.to/mabbasctn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mabbasctn"/>
    <language>en</language>
    <item>
      <title>JavaScript Hoisting Demystified: Elevate Your Coding Skills!</title>
      <dc:creator>Muhammad Abbas</dc:creator>
      <pubDate>Wed, 07 Aug 2024 18:20:23 +0000</pubDate>
      <link>https://dev.to/mabbasctn/javascript-hoisting-demystified-elevate-your-coding-skills-509n</link>
      <guid>https://dev.to/mabbasctn/javascript-hoisting-demystified-elevate-your-coding-skills-509n</guid>
      <description>&lt;p&gt;Hey there 👋 Let's talk about a JavaScript concept that might surprise you - Hoisting! 🤯&lt;/p&gt;

&lt;p&gt;Hoisting is all about how JavaScript handles variables and function declarations during the compilation phase.Basically, it moves them to the top of their scope, even before the code is executed. Wait, What!&lt;br&gt;
So, what does that mean in practice?&lt;br&gt;
Well, let's say you have this code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   `console.log(myVar);
   var myVar = "Hello, world!";
   // It outputs: `undefined`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Even though you're trying to log myVar before it's declared, the code still runs without any errors. That's because during the memory creation phase, myVar is assigned a default value of undefined. (You can refer to my last post where I wrote about &lt;a href="https://dev.to/mabbasctn/javascript-under-the-hood-embracing-its-single-threaded-strengths-345o"&gt;how JavaScript works&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;Let's take another example:&lt;br&gt;
        &lt;code&gt;myFun();&lt;br&gt;
        function myFun() { console.log("I am FuN"); }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this case, the whole function will store in memory. If you console it ( console.log(myFun) ), you will see the whole function will print out or run, and it will output &lt;code&gt;I am FuN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Pretty cool, right? Hoisting can have some interesting implications for your code, so it's important to understand how it works. 🤓 Let me know if you have any other JavaScript concepts you'd like to chat about!&lt;/p&gt;

&lt;p&gt;And last what about arrow functions? 🤔🤔🤔&lt;/p&gt;

&lt;p&gt;Its also treated like variable, store whole function in it. When you will try to call like myFun() before declaration you will experience error.&lt;/p&gt;

&lt;p&gt;Here is an example: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    `console.log("Before declaration myArrowFun: ", myArrowFun)
    var myArrowFun = () =&amp;gt; { console.log("I am Arrow FuN"); }
    console.log("After declaration myArrowFun: ", myArrowFun)
    console.log("Call declaration myArrowFun: ", myArrowFun())`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72nmbpo9429vb09x5lnz.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F72nmbpo9429vb09x5lnz.jpeg" alt="Image description" width="660" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
    <item>
      <title>JavaScript Under the Hood: Embracing Its Single-Threaded Strengths</title>
      <dc:creator>Muhammad Abbas</dc:creator>
      <pubDate>Tue, 30 Jul 2024 19:23:35 +0000</pubDate>
      <link>https://dev.to/mabbasctn/javascript-under-the-hood-embracing-its-single-threaded-strengths-345o</link>
      <guid>https://dev.to/mabbasctn/javascript-under-the-hood-embracing-its-single-threaded-strengths-345o</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbn52d8qjq58tniul4sq6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbn52d8qjq58tniul4sq6.png" alt="Image description" width="225" height="225"&gt;&lt;/a&gt;&lt;br&gt;
Ever wondered how JavaScript, one of the most popular programming language, works under the hood? 🤔&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded, meaning it executes one task at a time (think of it like a stack), line by line. 🕰️ But don't worry, this is actually a strength! Because it avoids the complexity of managing multiple threads, it reduces the risk of bugs like race conditions and deadlocks.&lt;/p&gt;

&lt;p&gt;JavaScript has two main phases of execution: the memory creation phase and the code execution phase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Creation Phase&lt;/strong&gt;: Before running your code, JavaScript first scans it to set up memory for variables and functions. This is called "hoisting," where declarations are moved to the top of their scope.&lt;br&gt;
Note: If you want to see this, simply create a .js file with some lines of code where you declare variables and functions. Then, open the developer console and move to application (code section) put a debugger at the beginning of your script. Then re-run the code, go in scope tab you'll see how JavaScript sets up memory for these declarations before executing the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Execution Phase&lt;/strong&gt;: Once memory is set up, JavaScript executes the code line by line. Functions and variables are assigned their values, and the code runs.&lt;/p&gt;

&lt;p&gt;Despite being single-threaded, JavaScript handles multiple tasks at once using an event loop. This loop manages asynchronous tasks like network requests or timers, ensuring the main thread remains free to keep your web app responsive and smooth. 🚀&lt;/p&gt;

&lt;p&gt;Next time you code in JavaScript, remember its single-threaded nature is a powerful feature. Embrace it to create amazing user experiences! 💻✨&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #programming #webdev #js #frontend
&lt;/h1&gt;

</description>
    </item>
  </channel>
</rss>
