<?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[My Learning Blogs]]></title><description><![CDATA[My Learning Blogs]]></description><link>https://theniranjan.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 01:58:20 GMT</lastBuildDate><atom:link href="https://theniranjan.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Execution Context]]></title><description><![CDATA[Have you ever wondered how JavaScript works behind the scenes? It's actually quite fascinating! And that's what you'll learn about here.
JavaScript is a single-threaded interpreted language. Every browser has its own JavaScript engine. Google Chrome ...]]></description><link>https://theniranjan.hashnode.dev/execution-context</link><guid isPermaLink="true">https://theniranjan.hashnode.dev/execution-context</guid><dc:creator><![CDATA[Niranjan Singh]]></dc:creator><pubDate>Tue, 18 Nov 2025 07:28:40 GMT</pubDate><content:encoded><![CDATA[<p>Have you ever wondered how JavaScript works behind the scenes? It's actually quite fascinating! And that's what you'll learn about here.</p>
<p>JavaScript is a single-threaded interpreted language. Every browser has its own JavaScript engine. Google Chrome has the V8 engine, Mozilla Firefox has SpiderMonkey, and so on. They all are used for the same goal, because the browsers cannot directly understand JavaScript code.</p>
<p>Let's look at an example so we can learn more:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> n = <span class="hljs-number">5</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">square</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">var</span> ans = n * n;
  <span class="hljs-keyword">return</span> ans;
}

<span class="hljs-keyword">var</span> square1 = square(n);
<span class="hljs-keyword">var</span> square2 = square(<span class="hljs-number">8</span>);  

<span class="hljs-built_in">console</span>.log(square1)
<span class="hljs-built_in">console</span>.log(square2)
</code></pre>
<p>In the above code,</p>
<ol>
<li><p>n is initialized and assigned a value of 5</p>
</li>
<li><p>We defined a function <code>square()</code> that accepts an argument n and returns the square of n.</p>
</li>
<li><p>We call the <code>square()</code> function and store the returned value in the <code>square1</code> variable.</p>
</li>
<li><p>We call the <code>square()</code> function and store the returned value in the <code>square2</code> variable.</p>
</li>
<li><p>Finally, it outputs both <code>square1</code> and <code>square2</code></p>
</li>
</ol>
<p>Behind the scenes, JavaScript is doing so many things. Let's understand all of it.</p>
<h2 id="heading-what-is-the-execution-context"><strong>What is the Execution Context?</strong></h2>
<p>When the JavaScript engine scans a script file, it makes an environment called the <strong>Execution Context</strong> that handles the entire transformation and execution of the code.</p>
<p>During the context runtime, the parser parses the source code and allocates memory for the variables and functions. The source code is generated and gets executed.</p>
<p>There are two types of execution contexts: <strong>global</strong> and <strong>function</strong>. The global execution context is created when a JavaScript script first starts to run, and it represents the global scope in JavaScript. A function execution context is created whenever a function is called, representing the function's local scope.</p>
<h3 id="heading-phases-of-the-javascript-execution-context"><strong>Phases of the JavaScript Execution Context</strong></h3>
<p>There are two phases of JavaScript execution context:</p>
<ol>
<li><p><strong>Creation phase</strong>: In this phase, the JavaScript engine creates the execution context and sets up the script's environment. It determines the values of variables and functions and sets up the scope chain for the execution context.</p>
</li>
<li><p><strong>Execution phase</strong>: In this phase, the JavaScript engine executes the code in the execution context. It processes any statements or expressions in the script and evaluates any function calls.</p>
</li>
</ol>
<p>Everything in JS happens inside this execution context. It is divided into two components. One is memory and the other is code. It is important to remember that these phases and components are applicable to both global and functional execution contexts.</p>
<h3 id="heading-creation-phase"><strong>Creation Phase</strong></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/1.png" alt="Image" /></p>
<p><em>Execution Context</em></p>
<p>Let's take this simple example once again:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> n = <span class="hljs-number">5</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">square</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">var</span> ans = n * n;
  <span class="hljs-keyword">return</span> ans;
}

<span class="hljs-keyword">var</span> square1 = square(n);
<span class="hljs-keyword">var</span> square2 = square(<span class="hljs-number">8</span>);  

<span class="hljs-built_in">console</span>.log(square1)
<span class="hljs-built_in">console</span>.log(square2)
</code></pre>
<p>At the very beginning, the JavaScript engine executes the entire source code, creates a global execution context, and then does the following things:</p>
<ol>
<li><p>Creates a global object that is <strong>window</strong> in the browser and <strong>global</strong> in NodeJs.</p>
</li>
<li><p>Sets up a memory for storing variables and functions.</p>
</li>
<li><p>Stores the variables with values as undefined and function references.</p>
</li>
</ol>
<p>This is called the creation phase. Here's a diagram to help explain it:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/untitled-2.png" alt="Image" /></p>
<p><em>Creation Phase in Execution Context</em></p>
<p>After this creation phase, the execution context will move to the code execution phase.</p>
<h3 id="heading-execution-phase"><strong>Execution Phase</strong></h3>
<p>Now, in this phase, it starts going through the entire code line by line from top to bottom. As soon as it encounters <strong>n = 5</strong>, it assigns the value 5 to 'n' in memory. Until now, the value of 'n' was undefined by default.</p>
<p>Then we get to the 'square' function. As the function has been allocated in memory, it directly jumps into the line <strong>var square1 = square(n);</strong>. square() will be invoked and JavaScript once again will create a new function execution context.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/untitled-3-1.png" alt="Image" /></p>
<p><em>Code Execution Phase</em></p>
<p>Once the calculation is done, it assigns the value of square in the 'ans' variable that was undefined before. The function will return the value, and the function execution context will be destroyed.</p>
<p>The returned value from square() will be assigned on square1. This happens for square2 also. Once the entire code execution is done completely, the global context will look like this and it will be destroyed also.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/untitled-4.png" alt="Image" /></p>
<h2 id="heading-what-is-the-call-stack"><strong>What is the Call Stack?</strong></h2>
<p>To keep the track of all the contexts, including global and functional, the JavaScript engine uses a <strong>call stack</strong>. A call stack is also known as an 'Execution Context Stack', 'Runtime Stack', or 'Machine Stack'.</p>
<p>It uses the LIFO principle (Last-In-First-Out). When the engine first starts executing the script, it creates a global context and pushes it on the stack. Whenever a function is invoked, similarly, the JS engine creates a function stack context for the function and pushes it to the top of the call stack and starts executing it.</p>
<p>When execution of the current function is complete, then the JavaScript engine will automatically remove the context from the call stack and it goes back to its parent.</p>
<p>Let's see the following example:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">funcA</span>(<span class="hljs-params">m,n</span>) </span>{
    <span class="hljs-keyword">return</span> m * n;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">funcB</span>(<span class="hljs-params">m,n</span>) </span>{
    <span class="hljs-keyword">return</span> funcA(m,n);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getResult</span>(<span class="hljs-params">num1, num2</span>) </span>{
    <span class="hljs-keyword">return</span> funcB(num1, num2)
}

<span class="hljs-keyword">var</span> res = getResult(<span class="hljs-number">5</span>,<span class="hljs-number">6</span>);

<span class="hljs-built_in">console</span>.log(res); <span class="hljs-comment">// 30</span>
</code></pre>
<p>In this example, the JS engine creates a global execution context that enters the creation phase.</p>
<p>First it allocates memory for <code>funcA</code>, <code>funcB</code>, the <code>getResult</code> function, and the <code>res</code> variable. Then it invokes <code>getResult()</code>, which will be pushed on the call stack.</p>
<p>Then <code>getResult()</code> will call <code>funcB()</code>. At this point, <code>funcB</code>'s context will be stored on the top of the stack. Then it will start executing and call another function <code>funcA()</code>. Similarly, <code>funcA</code>'s context will be pushed.</p>
<p>Once execution of each function is done, it will be removed from the call stack. The following picture depicts the entire process of the execution:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/5.png" alt="Image" /></p>
<p><em>Call Stack</em></p>
<p>The call stack has its own fixed size depending on the system or browser. If the number of contexts exceeds the limit, then a stack overflow error will occur. This happens with a recursive function that has no base condition.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">display</span>(<span class="hljs-params"></span>) </span>{
    display();
}

display();
</code></pre>
<pre><code class="lang-bash">C:\Users\rwiteshbera\Desktop\Javascript\n.js:2
    display();
    ^
RangeError: Maximum call stack size exceeded
</code></pre>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>In conclusion, JavaScript execution context is a crucial part of understanding how JavaScript works behind the scenes. It determines the environment in which code is executed and what variables and functions are available to use.</p>
]]></content:encoded></item><item><title><![CDATA[GPT Explained Like You're 5: The Kid-Friendly Guide to AI]]></title><description><![CDATA[What is GPT? (Explained for a 5-Year-Old)
Have you ever talked to a computer that talks back like a person? That’s kind of what GPT is. But to understand it, let’s imagine…
The Magical Parrot
Picture a talking parrot.But this isn’t just any parrot, t...]]></description><link>https://theniranjan.hashnode.dev/gpt-explained-like-youre-5-the-kid-friendly-guide-to-ai</link><guid isPermaLink="true">https://theniranjan.hashnode.dev/gpt-explained-like-youre-5-the-kid-friendly-guide-to-ai</guid><dc:creator><![CDATA[Niranjan Singh]]></dc:creator><pubDate>Fri, 15 Aug 2025 14:34:53 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-is-gpt-explained-for-a-5-year-old"><strong>What is GPT? (Explained for a 5-Year-Old)</strong></h2>
<p>Have you ever talked to a computer that talks back like a person? That’s kind of what GPT is. But to understand it, let’s imagine…</p>
<h2 id="heading-the-magical-parrot">The Magical Parrot</h2>
<p>Picture a talking parrot.<br />But this isn’t just any parrot, this parrot has read every storybook, comic, newspaper, and joke book in the world. It’s heard every bedtime story, every “Knock Knock” joke, and even that weird poem your uncle made up last Christmas.<br />Now, if you ask the parrot:</p>
<p><strong>"Tell me a story about a dinosaur who loves pizza"</strong></p>
<p>it can make one up for you on the spot, using everything it’s read before.<br />That’s basically what GPT does… except GPT is not a bird. It’s a computer brain built by very smart people. It has read millions of pages from the internet, books, and articles. Then it learned how to guess the next word in a sentence really, really well.</p>
<h2 id="heading-how-it-works">How It Works</h2>
<p>Think of GPT like Lego blocks but instead of plastic blocks, it has words. When you start a sentence, GPT picks the next “word block” that fits best. Then another. And another. Until you’ve built a whole castle made of words.</p>
<p>Example:<br />You say: <strong>“Once upon a time, there was a…”</strong><br />GPT might finish: <strong>“…little dragon who loved painting rainbows.”</strong></p>
<p>Why? Because it’s seen lots of stories like that, and it knows dragons and rainbows often go together in stories.</p>
<h2 id="heading-why-is-it-called-gpt">Why Is It Called GPT?</h2>
<ul>
<li><p><strong>G – Generative:</strong> It makes (generates) new text.</p>
</li>
<li><p><strong>P – Pre-trained:</strong> It learned a ton before you even talked to it.</p>
</li>
<li><p><strong>T – Transformer:</strong> A fancy computer trick that helps it understand how words connect.</p>
</li>
</ul>
<p>So, <strong>GPT = “A computer that’s good at making sentences.”</strong></p>
<h2 id="heading-what-can-gpt-do">What Can GPT Do?</h2>
<ul>
<li><p>Tell bedtime stories.</p>
</li>
<li><p>Make up silly poems.</p>
</li>
<li><p>Help With Homework.</p>
</li>
<li><p>Answer questions like <strong>“Why is the sky blue?”</strong> or <strong>“Do cats have eyebrows?”</strong></p>
</li>
</ul>
<p>(Yes, cats do have tiny eyebrow-like whiskers.)</p>
<h2 id="heading-why-it-feels-like-magic">Why It Feels Like Magic</h2>
<p>GPT doesn’t just copy what it’s read, it mixes ideas together. Like blending chocolate cake and strawberry ice cream to make chocolate-strawberry cake!<br />So even if you ask it something it’s never seen before, it can still give you an answer.</p>
<h2 id="heading-the-big-secret">The Big Secret</h2>
<p>Even though GPT seems super smart, it doesn’t really understand things like humans do. It’s more like your friend who’s great at finishing your sentences but doesn’t actually know what you’re thinking. It’s amazing with words, but it doesn’t have feelings or thoughts.</p>
<h2 id="heading-summary">Summary</h2>
<p>GPT is like a magical parrot with a library for a brain, a super-talking computer that can make up stories, answer your questions, and play with words.</p>
<p>So next time you chat with GPT, remember: it’s not magic… but it’s pretty close.</p>
]]></content:encoded></item></channel></rss>