<?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 sruthi ragupathy on Medium]]></title>
        <description><![CDATA[Stories by sruthi ragupathy on Medium]]></description>
        <link>https://medium.com/@sruthiragupathy?source=rss-f635c9a6b7d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZyDunJ9VHOkilA8N</url>
            <title>Stories by sruthi ragupathy on Medium</title>
            <link>https://medium.com/@sruthiragupathy?source=rss-f635c9a6b7d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:26:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sruthiragupathy/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[Var vs Let vs Const in javascript]]></title>
            <link>https://medium.com/@sruthiragupathy/var-vs-let-vs-const-in-javascript-3ffa9cd4aa72?source=rss-f635c9a6b7d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ffa9cd4aa72</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[keywords]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[sruthi ragupathy]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 10:23:42 GMT</pubDate>
            <atom:updated>2020-08-08T10:23:42.275Z</atom:updated>
            <content:encoded><![CDATA[<h3>Var vs Let vs Const in Javascript</h3><p><a href="https://dev.to/t/javascript">#javascript</a> <a href="https://dev.to/t/keywords">#keywords</a></p><p>Before speaking about the keywords var,let and const, I believe it is extremely important to understand the concept of scope.</p><h3>Global Scope</h3><p>Variables declared <strong>outside any function</strong> (globally) have global scope</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*3LlEgzssrarA7iAg.PNG" /></figure><p>Here, the variable global can be accessed from anywhere.</p><h3>Function Scope</h3><p>Variables that are declared <strong>inside a function</strong> (locally) have function scope</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*IWlLydiO6WkZxOr7.PNG" /></figure><p>Here, the variable local can be accessed only inside the function.</p><h3>Block Scope</h3><p>Some variables can be accessed only <strong>within block</strong> i.e.,within {}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*-WX5Ez88LAz6JPkg.PNG" /></figure><p>Here , the variable <strong>block</strong> can be accessed only within the if block. It cannot be accessed from anywhere else. Thus, the variable <strong>block</strong> has only block scope.</p><p>Now that we are clear with the scope, let’s dive into the <strong>var,let and const</strong> keywords</p><h3><strong>var</strong></h3><h4>Scope</h4><p>The variables defined with the keyword <strong>var</strong> have <strong>function</strong> scope.If it is defined outside the function , then the scope of the variable is <strong>global</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*r8iJ1yg--Q3aIKrx.PNG" /></figure><p>Here, the variable <strong>foo</strong> defined with the keyword <strong>var</strong> can be accessed from anywhere while the variable <strong>bar</strong> is limited to the function scope.</p><h4>Redeclaration and ReAssignment</h4><p>The variables declared with the keyword <strong>var</strong> can be redeclared and reassigned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*s5jrbcwIF-OBSdIx.PNG" /></figure><h4>Hoisting</h4><p>Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.</p><p>Variables declared with <strong>var</strong> keyword are hoisted at the top of its scope and is initialized with <strong>undefined</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*3nGN8ggtcHZjLoI0.PNG" /></figure><p>Here, the variable <strong>foo</strong> is declared later.But it is hoisted at the top and initialized to undefined.</p><h3>let</h3><h3>Scope</h3><p>The variables declared with the keyword <strong>let</strong> have <strong>block</strong> scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*PgZfiVaZ2-Wo4wg_.PNG" /></figure><p>Here, the variable <strong>i</strong> can be accessed only within the <strong>for</strong> loop.</p><h4>Redeclaration and ReAssignment</h4><p>Variables declared with <strong>let</strong> keyword cannot be redeclared, but it can be reassigned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*LMU8eMtFwQg7GF-I.PNG" /></figure><h4>Hoisting</h4><p>Variables declared with <strong>let</strong> are also hoisted at the top, but let variables are not initialized until their definition is evaluated.This is because of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let">Temporal Dead Zone</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*e7FGfGIoEm5XTMo1.PNG" /></figure><p>Thus,trying to access the variable <strong>foo</strong> before declaration gives reference error.</p><h3>const</h3><h4>Scope</h4><p>The variables declared with the <strong>const</strong> keyword also have block scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*NIysUuCFMezHsY3o.PNG" /></figure><h4>Redeclaration and Reassignment</h4><p>Variables declared with <strong>const</strong> keyword must be initialized at the time of its declaration itself.Otherwise an error is thrown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*yKEfNHaZq9br1ker.PNG" /></figure><p>Variables declared with <strong>const</strong> keyword cannot be redeclared and reassigned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*lDpNvKp9e6-djiBP.PNG" /></figure><p>Attempting to overwrite objects with const keyword throws error. But object keys are not protected and they are mutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*cDgW-m8vpjVpk8qc.PNG" /></figure><p>Here, we can see that the object cannot be reassigned, but the keys of the object are mutable.</p><p>Similarly arrays declared with const keyword cannot be overwritten. But the elements in the array is mutable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Y-EydSpmbkTdmPTi.PNG" /></figure><h4>Hoisting</h4><p>Variables declared with <strong>const</strong> keyword behaves the same way as <strong>let</strong> keyword.They are hoisted at the top of the scope but they are not initialized until their definition is evaluated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*UV4eG46lAs1-zRXw.PNG" /></figure><h3>var vs let vs const — A Summary</h3><p>varletconstScopeFunction or GlobalBlockBlockRedeclareYesNoNoReassignYesYesNoHoistedYesNoNo</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ffa9cd4aa72" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>