<?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 Naincy Rathore on Medium]]></title>
        <description><![CDATA[Stories by Naincy Rathore on Medium]]></description>
        <link>https://medium.com/@naincyrathore543?source=rss-3c2a6f8cd4b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xRDd6PYFYLY-wtgz</url>
            <title>Stories by Naincy Rathore on Medium</title>
            <link>https://medium.com/@naincyrathore543?source=rss-3c2a6f8cd4b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:45:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naincyrathore543/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[Unveiling JavaScript Closures: A Window into Lexical Scope]]></title>
            <link>https://naincyrathore543.medium.com/unveiling-javascript-closures-a-window-into-lexical-scope-0c62f92ed17f?source=rss-3c2a6f8cd4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c62f92ed17f</guid>
            <category><![CDATA[closure]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[lexical-scope]]></category>
            <category><![CDATA[scope-chains]]></category>
            <category><![CDATA[closure-in-javascript]]></category>
            <dc:creator><![CDATA[Naincy Rathore]]></dc:creator>
            <pubDate>Thu, 21 Dec 2023 12:36:26 GMT</pubDate>
            <atom:updated>2023-12-21T12:36:26.611Z</atom:updated>
            <content:encoded><![CDATA[<p>Closures in JavaScript are akin to magic doors that allow functions to retain knowledge of their surrounding environment. At their core, closures are the symbiotic relationship between a function and its lexical scope. Let’s delve into this enchanting aspect of JavaScript and grasp the concept of closures with a tangible example.</p><blockquote><strong><em>Understanding Closures: The Basics</em></strong></blockquote><p>In essence, a closure occurs when a function is defined within another function, creating a bridge between the inner function and its outer (lexical) scope. This grants the inner function the remarkable ability to remember and access variables and functions from its birthplace.</p><p>Consider the following example:</p><pre>function outerFunction() {<br> let outerVariable = &quot;I am outside!&quot;;<br>function innerFunction() {<br> console.log(outerVariable);<br> }<br>return innerFunction;<br>}<br>const closureExample = outerFunction();<br>closureExample(); // Outputs: &quot;I am outside!&quot;</pre><p>In this scenario, `outerFunction` encapsulates `innerFunction`. When `outerFunction` is invoked and assigned to `closureExample`, it essentially carries with it the context of its creation, including the `outerVariable`. Even when invoked outside its original scope, `innerFunction` retains access to `outerVariable`.</p><blockquote><strong><em>Practical Use Cases:</em></strong></blockquote><p>Closures are not just a mesmerizing concept; they have practical applications in JavaScript:</p><ol><li><strong>Data Privacy: </strong>Closures provide a means to create private variables, safeguarding them from unintended external access.</li></ol><pre>function secretKeeper() {<br> let secret = &quot;Shh… it&#39;s a secret!&quot;;<br>return {<br> getSecret: function() {<br> return secret;<br> }<br> };<br> }<br>const mySecretKeeper = secretKeeper();<br> console.log(mySecretKeeper.getSecret()); // Outputs: &quot;Shh… it&#39;s a secret!&quot;</pre><p>2. <strong>Function Factories: </strong>Closures enable the creation of functions tailored to specific scenarios, often referred to as function factories.</p><pre>function multiplier(factor) {<br> return function(number) {<br> return number * factor;<br> };<br> }<br>const double = multiplier(2);<br> console.log(double(5)); // Outputs: 10</pre><blockquote><strong><em>Conclusion:</em></strong></blockquote><p>In the realm of JavaScript, closures add a layer of elegance and versatility to our code. They empower functions with memory, allowing them to traverse time and space within their lexical scope. Embrace closures, and you’ll find yourself wielding a powerful tool for crafting clean, modular, and efficient JavaScript code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c62f92ed17f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding JavaScript Variables: var vs let vs const]]></title>
            <link>https://naincyrathore543.medium.com/understanding-javascript-variables-var-vs-let-vs-const-9e0eddc8d86d?source=rss-3c2a6f8cd4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e0eddc8d86d</guid>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[hoisting]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Naincy Rathore]]></dc:creator>
            <pubDate>Fri, 15 Dec 2023 10:10:04 GMT</pubDate>
            <atom:updated>2023-12-15T10:10:04.891Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Understanding JavaScript Variables: var </strong>vs<strong> let </strong>vs<strong> const</strong></p><p>JavaScript provides three primary ways to declare variables: <strong>var</strong>, <strong>let</strong>, and <strong>const</strong>. Each has its distinct characteristics, and understanding their differences is crucial for writing robust and maintainable code.</p><p>1.<strong> var: The Traditional Player</strong></p><p><strong>var</strong> was the original variable declaration keyword in JavaScript. It has function-level scope, meaning it is limited to the function where it’s declared or, if not in a function, it becomes a global variable.</p><pre>function exampleVar() {<br> if (true) {<br> var x = 10;<br> }<br> console.log(x); // Outputs 10, as var has function-level scope<br>}</pre><p>2. <strong>let: Introducing Block Scope</strong></p><p><strong>let</strong> was introduced in ECMAScript 6 (ES6) to address some issues with <strong>var</strong>. It has block-level scope, confining the variable to the block, statement, or expression where it is declared.</p><pre>function exampleLet() {<br> if (true) {<br> let y = 20;<br> }<br> console.log(y); // Throws an error, as let has block-level scope<br>}</pre><p>3. <strong>const: Constants for Stability</strong></p><p><strong>const</strong> is used to declare constants, and like <strong>let</strong>, it also has block-level scope. Once a value is assigned to a <strong>const</strong>, it cannot be reassigned.</p><pre>function exampleConst() {<br> const z = 30;<br> z = 40; // Throws an error, as const values cannot be reassigned<br>}</pre><p><strong>When to Use Which?</strong></p><ul><li>Use <strong>var</strong> if you need a variable with function-level scope, but be cautious due to potential issues like variable hoisting.</li><li>Prefer <strong>let</strong> for variables with block-level scope, especially when the variable may need to be reassigned.</li><li>Use <strong>const</strong> for constants or variables that shouldn’t be reassigned. It helps in writing more predictable and error-resistant code.</li></ul><p><strong>Conclusion</strong></p><p>Understanding the differences between <strong>var</strong>, <strong>let</strong>, and <strong>const</strong> is essential for writing clean and bug-free JavaScript code. Choose the right variable declaration based on the scope and mutability requirements of your variables.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e0eddc8d86d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying Execution Context and the Call Stack in JavaScript]]></title>
            <link>https://naincyrathore543.medium.com/demystifying-execution-context-and-the-call-stack-in-javascript-7e6e817261d3?source=rss-3c2a6f8cd4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e6e817261d3</guid>
            <category><![CDATA[code-comments]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[global-execution-context]]></category>
            <category><![CDATA[execution-context]]></category>
            <category><![CDATA[call-stack]]></category>
            <dc:creator><![CDATA[Naincy Rathore]]></dc:creator>
            <pubDate>Thu, 12 Oct 2023 14:40:54 GMT</pubDate>
            <atom:updated>2023-10-12T14:56:56.859Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is a versatile and widely used programming language, known for its asynchronous and event-driven nature. To understand how JavaScript code is executed, it’s crucial to grasp the concepts of execution context, the call stack, and their inner workings. In this article, I’ll break down these concepts in simple terms and provide clear examples.</p><blockquote><strong>Execution Context: The Key Player</strong></blockquote><p>In JavaScript, an execution context is like a container that holds all the information necessary to execute a piece of code. There are three types of execution contexts in JavaScript:</p><p>1. <strong>Global Execution Context:</strong> This is the default context and represents the code in the global scope, such as code outside of any function.</p><p>2. <strong>Function Execution Context:</strong> Each time a function is called, a new function execution context is created. It holds information about the function’s parameters, variables, and the function’s code.</p><p>3. <strong>Evaluating Execution Context:</strong> When JavaScript is evaluating an expression, it creates an evaluating execution context. This happens when, for example, you’re using `eval()` to execute code.</p><blockquote><strong>Execution Context Components</strong></blockquote><p>Each execution context consists of two main components:</p><p>1. <strong>Code Component:</strong> This part contains the actual JavaScript code to be executed. It includes the function’s instructions, variable declarations, and any function calls within that context.</p><p>2. <strong>Memory Component (</strong>Variable Environment<strong>):</strong> Here, JavaScript stores variables and functions declarations. The memory component holds the values of variables, parameters, and references to functions available within the current context.</p><blockquote><strong>The Call Stack: Keeping Track of Execution</strong></blockquote><p>Now that we understand execution contexts let’s explore how JavaScript keeps track of them using the call stack. The call stack is a mechanism that helps manage the order in which functions are executed.</p><p>Whenever a function is called, a new function execution context is created, and it is pushed onto the call stack. As the function completes, it is popped off the stack, and the control returns to the previous context.</p><p>Let’s see this in action with a simple example:</p><pre>function greet(name) {<br> console.log(&quot;Hello, &quot; + name + &quot;!&quot;);<br>}<br>function sayHello() {<br> const user = &quot;Alice&quot;;<br> greet(user);<br> console.log(&quot;This is the end.&quot;);<br>}<br>sayHello();</pre><p>In this code snippet, we have two functions: sayHello and greet. When sayHello is called, it sets the user variable to &quot;Alice&quot; and then calls the greet function with &quot;Alice&quot; as an argument. As these functions execute, they create and remove function execution contexts on the call stack.</p><p>The expected output when running this code is:</p><pre>Hello, Alice! <br>This is the end.</pre><p>1. The `sayHello` function is called, creating a new function execution context for it, which is pushed onto the call stack.</p><p>2. Inside `sayHello`, the `greet` function is called, resulting in a new function execution context for `greet`, which is pushed onto the call stack.</p><p>3. The `greet` function executes and is removed from the call stack.</p><p>4. Control returns to the `sayHello` function, which continues to execute. Once done, it is also removed from the call stack.</p><p>5. Finally, the global execution context remains on the call stack until the program completes.</p><blockquote><strong>Conclusion:</strong></blockquote><p>Understanding execution context and the call stack is essential for writing efficient and error-free JavaScript code. It helps you comprehend the flow of your code, handle function calls, and troubleshoot issues. As you continue your JavaScript journey, these concepts will become second nature, and you’ll be better equipped to work with this powerful language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e6e817261d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Hoisting In Javascript]]></title>
            <link>https://naincyrathore543.medium.com/understanding-hoisting-in-javascript-27321e34505d?source=rss-3c2a6f8cd4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/27321e34505d</guid>
            <category><![CDATA[function-hoisting]]></category>
            <category><![CDATA[var-let-const-difference]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[hoisting]]></category>
            <dc:creator><![CDATA[Naincy Rathore]]></dc:creator>
            <pubDate>Thu, 12 Oct 2023 14:28:10 GMT</pubDate>
            <atom:updated>2023-11-13T09:01:08.930Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript, the programming language of the web, offers powerful tools to create dynamic and interactive web pages. However, it also has some quirks that can trip up even experienced developers. One of those quirks is “hoisting.” In this article, we’ll demystify hoisting in JavaScript with straightforward examples and clear explanations.</p><p><strong>What is Hoisting?</strong></p><p>Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope during the compilation phase. This means that you can use variables and functions before they are declared in your code.</p><p>Let’s dive into a few examples to understand how hoisting works:</p><p><strong>Variable Hoisting:</strong></p><p>console.log(age);</p><p>var age = 25;</p><p>// Output: undefined</p><p>In the code above, even though we’re trying to log the `age` variable before declaring it, JavaScript doesn’t throw an error. Instead, it gets hoisted to the top of its scope, which means the code is effectively interpreted as:</p><p>var age;<br>console.log(age);<br>age = 25;</p><p>// Output: undefined</p><p>As a result, `age` is initially `undefined` because only the declaration, not the assignment, is hoisted. To avoid this behavior, always declare your variables at the beginning of their scope.</p><p><strong>Function Hoisting:</strong></p><p>Function declarations are also hoisted, which means you can call a function before declaring it:</p><p>greet();</p><p>function greet() {<br> console.log(“Hello!”);<br>}</p><p>// Output: Hello!</p><p>Here, `greet` is called before the function declaration, but JavaScript hoists the function declaration to the top of the scope, making the code equivalent to:</p><p>function greet() {<br> console.log(“Hello!”);<br>}</p><p>greet();</p><p>// Output: Hello!</p><p><strong>Hoisting with let and const:</strong></p><p>Hoisting works differently for variables declared with `let` and `const`. While they are hoisted, they are not initialized with `undefined` like `var`. Instead, you get a “ReferenceError” if you try to access them before declaration:</p><p>console.log(name); <br>let name = “Alice”;</p><p>// Throws a ReferenceError</p><p><strong>Best Practices:</strong></p><p>To write clean and understandable code, follow these best practices:</p><p>1. Declare your variables at the beginning of their scope.<br>2. Use `let` and `const` instead of `var` to avoid unintentional hoisting-related issues.<br>3. Always declare functions before using them, even though hoisting allows you to call them before declaration.</p><p><strong>Conclusion:</strong></p><p>Understanding hoisting is crucial in JavaScript to avoid unexpected behavior in your code. Remember that variable and function declarations are hoisted to the top of their containing scope. Using `var`, `let`, and `const` appropriately, and declaring functions before use, will help you write clean and predictable JavaScript code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27321e34505d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>