<?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"><channel><title><![CDATA[Nasir's Tech Talk]]></title><description><![CDATA[Hey, I’m Nasir—a developer who loves learning and sharing tech stuff in simple, practical ways.

"Be the senior you needed as a junior"]]></description><link>https://blog.hellonasir.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 04:31:03 GMT</lastBuildDate><atom:link href="https://blog.hellonasir.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[JavaScript Hoisting Explained]]></title><description><![CDATA[Hoisting is one of the most misunderstood concepts in JavaScript. Many developers think JavaScript “moves variables and functions to the top of the file.” That explanation is convenient—but technically wrong.
In this article, we’ll break down what ac...]]></description><link>https://blog.hellonasir.dev/javascript-hoisting-explained</link><guid isPermaLink="true">https://blog.hellonasir.dev/javascript-hoisting-explained</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Hoisting]]></category><dc:creator><![CDATA[Nasir Ahmed]]></dc:creator><pubDate>Tue, 17 Feb 2026 07:57:08 GMT</pubDate><content:encoded><![CDATA[<p>Hoisting is one of the most misunderstood concepts in JavaScript. Many developers think JavaScript “moves variables and functions to the top of the file.” That explanation is convenient—but technically wrong.</p>
<p>In this article, we’ll break down <strong>what actually happens under the hood</strong>, why <code>var</code>, <code>let</code>, and <code>const</code> behave differently, and how the <strong>Temporal Dead Zone (TDZ)</strong> fits into the picture.</p>
<hr />
<h2 id="heading-the-global-execution-context">The Global Execution Context</h2>
<p>When a JavaScript program starts, the engine creates a <strong>Global Execution Context (GEC)</strong>.</p>
<p>The GEC is created in <strong>two phases</strong>:</p>
<ol>
<li><p><strong>Creation Phase</strong></p>
</li>
<li><p><strong>Execution Phase</strong></p>
</li>
</ol>
<p>Understanding hoisting starts with the <strong>creation phase</strong>.</p>
<hr />
<h2 id="heading-what-happens-in-the-creation-phase">What Happens in the Creation Phase?</h2>
<p>During the creation phase, JavaScript does the following:</p>
<ul>
<li><p>Creates the <code>window</code> object (in browsers)</p>
</li>
<li><p>Initializes the <code>this</code> keyword</p>
<ul>
<li>In global scope, <code>this === window</code></li>
</ul>
</li>
<li><p>Allocates memory for:</p>
<ul>
<li><p>Variables</p>
</li>
<li><p>Functions</p>
</li>
</ul>
</li>
</ul>
<p>This memory allocation step is what we call <strong>hoisting</strong>.</p>
<hr />
<h2 id="heading-variable-hoisting">Variable Hoisting</h2>
<h3 id="heading-var-variables"><code>var</code> Variables</h3>
<ul>
<li><p>Memory is allocated during the creation phase</p>
</li>
<li><p>Automatically initialized with <code>undefined</code></p>
</li>
<li><p>Can be accessed before declaration (value will be <code>undefined</code>)</p>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(a); <span class="hljs-comment">// undefined</span>
<span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
</code></pre>
<p>This behavior is why <code>var</code> is considered unsafe in many scenarios.</p>
<hr />
<h3 id="heading-let-and-const-variables"><code>let</code> and <code>const</code> Variables</h3>
<ul>
<li><p>Memory <strong>is allocated</strong> during the creation phase</p>
</li>
<li><p>They are <strong>not initialized</strong></p>
</li>
<li><p>They remain in the <strong>Temporal Dead Zone (TDZ)</strong></p>
</li>
<li><p>Accessing them before declaration results in a <strong>ReferenceError</strong></p>
</li>
</ul>
<blockquote>
<p>Important: <code>let</code> and <code>const</code> <strong>are hoisted</strong>, but they are not initialized.</p>
</blockquote>
<hr />
<h2 id="heading-understanding-the-temporal-dead-zone-tdz">Understanding the Temporal Dead Zone (TDZ)</h2>
<p>The <strong>Temporal Dead Zone</strong> is one of the most confusing parts of JavaScript.</p>
<ul>
<li><p>TDZ is <strong>not a physical place</strong></p>
</li>
<li><p>It is a <strong>time period</strong></p>
</li>
<li><p>It exists from:</p>
<ul>
<li><p>Scope creation</p>
</li>
<li><p>Until the variable declaration is executed</p>
</li>
</ul>
</li>
</ul>
<p>Once the declaration line runs, the TDZ ends.</p>
<pre><code class="lang-javascript">{
    <span class="hljs-comment">// === name variable's TDZ started here</span>
    <span class="hljs-keyword">let</span> name;
    <span class="hljs-comment">// console.log(name); // RerenceError</span>
    <span class="hljs-comment">// some code</span>
    <span class="hljs-comment">// some code</span>
    name = <span class="hljs-string">"tapaScript"</span> <span class="hljs-comment">// === name variable's TDZ ends here</span>
    <span class="hljs-built_in">console</span>.log(name);
    <span class="hljs-comment">//</span>
    <span class="hljs-comment">//</span>
}
</code></pre>
<p>For <code>const</code>, initialization must happen at the declaration line, otherwise JavaScript throws an error.</p>
<hr />
<h2 id="heading-function-hoisting">Function Hoisting</h2>
<h3 id="heading-function-declarations">Function Declarations</h3>
<ul>
<li><p>Entire function is stored in memory during the creation phase</p>
</li>
<li><p>Can be called before the function declaration appears in code</p>
</li>
</ul>
<pre><code class="lang-javascript">greet(); <span class="hljs-comment">// "Hello"</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello"</span>);
}
</code></pre>
<p>This is known as <strong>full hoisting</strong>.</p>
<hr />
<h3 id="heading-function-expressions">Function Expressions</h3>
<p>Function expressions behave like variables.</p>
<ul>
<li><p>Hoisting depends on how they are declared (<code>var</code>, <code>let</code>, <code>const</code>)</p>
</li>
<li><p>They are <strong>not callable</strong> before initialization</p>
</li>
</ul>
<pre><code class="lang-javascript">sayHi(); <span class="hljs-comment">// Uncaught TypeError: sayHi is not a function</span>

<span class="hljs-keyword">var</span> sayHi = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hi"</span>);
};
</code></pre>
<hr />
<h2 id="heading-execution-phase">Execution Phase</h2>
<p>After the creation phase finishes:</p>
<ul>
<li><p>JavaScript enters the <strong>execution phase</strong></p>
</li>
<li><p>Code runs line by line</p>
</li>
<li><p>Variable assignments happen here</p>
</li>
<li><p>Function calls are executed here</p>
</li>
</ul>
<hr />
<h2 id="heading-so-what-is-hoisting-really">So, What Is Hoisting Really?</h2>
<p>❌ Hoisting is <strong>not</strong> JavaScript moving code to the top<br />✅ Hoisting is <strong>memory allocation before execution</strong></p>
<ul>
<li><p>Variable hoisting → memory created for variables</p>
</li>
<li><p>Function hoisting → memory created for functions</p>
</li>
</ul>
<p>Nothing is physically moved in your source code.</p>
]]></content:encoded></item><item><title><![CDATA[ref.current : Why is often null?]]></title><description><![CDATA[When working with React, especially when using refs, many developers run into this common issue:

"Why is ref.current null even though I just attached it to a DOM element?"

Let’s clear up the confusion by understanding how React updates the UI in tw...]]></description><link>https://blog.hellonasir.dev/ref-current-why-is-often-null</link><guid isPermaLink="true">https://blog.hellonasir.dev/ref-current-why-is-often-null</guid><category><![CDATA[React]]></category><category><![CDATA[useRef]]></category><category><![CDATA[useRef Hook]]></category><dc:creator><![CDATA[Nasir Ahmed]]></dc:creator><pubDate>Wed, 28 May 2025 10:20:57 GMT</pubDate><content:encoded><![CDATA[<p>When working with React, especially when using <strong>refs</strong>, many developers run into this common issue:</p>
<blockquote>
<p>"Why is <code>ref.current</code> null even though I just attached it to a DOM element?"</p>
</blockquote>
<p>Let’s clear up the confusion by understanding how React updates the UI in <strong>two distinct phases</strong>:</p>
<ol>
<li><p>Render</p>
</li>
<li><p>Commit</p>
</li>
</ol>
<p>Imagine React is like a builder and a Planner who building a house (your UI). It does it in two steps:</p>
<hr />
<ol>
<li><strong>Planning Phase (Render)</strong></li>
</ol>
<p>React (the architect) is planning:</p>
<ul>
<li><p>“Where should the doors go?”</p>
</li>
<li><p>“Where should the windows be?”</p>
</li>
</ul>
<p>But</p>
<ul>
<li><p>The house isn’t <strong>build yet.</strong></p>
</li>
<li><p>So if you try to “open a door” during this step, it won't work — it <strong>doesn’t exist yet</strong>!</p>
</li>
</ul>
<p>This is like trying to access <code>ref.current</code> during rendering — it's either <code>null</code> or not correct yet.</p>
<hr />
<ol start="2">
<li><strong>Building Phase (Commit)</strong></li>
</ol>
<p>Now React (the builder) actually builds:</p>
<ul>
<li><p>Puts the doors, windows, roof, etc., in place.</p>
</li>
<li><p>Once the house is done, you can now open the door!</p>
</li>
</ul>
<p>his is like after the DOM is built — your <code>ref.current</code> now points to the real thing.</p>
<hr />
<p>Let’s visualise this steps:</p>
<pre><code class="lang-plaintext">[Render Phase] (Planning)
------------------------------------------------
| React runs your components                  |
| No DOM yet (just planning)                  |
| ref.current = null or old value             |
------------------------------------------------

[Commit Phase] (Building)
------------------------------------------------
| React updates the DOM                       |
| - First, it clears old refs (null them out) |
| - Then, builds DOM elements                 |
| - Then, sets ref.current to new elements    |
------------------------------------------------
</code></pre>
<p>That’s all for today. Feel free to share your thoughts or questions if you found this article helpful.</p>
]]></content:encoded></item><item><title><![CDATA[Don't mess with Javascript]]></title><description><![CDATA[Javascript; the ultimate game changer.
JavaScript has emerged as the ultimate game-changer in the world of technology, revolutionizing how we interact with the web and shaping the digital landscape in unprecedented ways. Introduced in 1995, JavaScrip...]]></description><link>https://blog.hellonasir.dev/dont-mess-with-javascript</link><guid isPermaLink="true">https://blog.hellonasir.dev/dont-mess-with-javascript</guid><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Nasir Ahmed]]></dc:creator><pubDate>Tue, 31 Dec 2024 11:58:57 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-javascript-the-ultimate-game-changer">Javascript; the ultimate game changer.</h3>
<p>JavaScript has emerged as the ultimate game-changer in the world of technology, revolutionizing how we interact with the web and shaping the digital landscape in unprecedented ways. Introduced in 1995, JavaScript began as a simple scripting language to add interactivity to web pages. Over the decades, it has evolved into a powerful and versatile programming language capable of powering everything from dynamic websites to complex applications. Its flexibility allows developers to create rich, responsive user interfaces, enhancing user experiences across all devices. Libraries and frameworks like React, Angular, and Vue.js have further propelled JavaScript into the forefront, enabling developers to build sophisticated front-end architectures with ease.</p>
]]></content:encoded></item></channel></rss>