<?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: Shaurya Jain</title>
    <description>The latest articles on DEV Community by Shaurya Jain (@shaur).</description>
    <link>https://dev.to/shaur</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%2F811262%2F52039589-0831-4c51-b3b7-ee3a4fcb4e8a.jpg</url>
      <title>DEV Community: Shaurya Jain</title>
      <link>https://dev.to/shaur</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shaur"/>
    <language>en</language>
    <item>
      <title>Scopes in Javascript with DevTools</title>
      <dc:creator>Shaurya Jain</dc:creator>
      <pubDate>Thu, 24 Mar 2022 13:05:49 +0000</pubDate>
      <link>https://dev.to/shaur/scopes-in-javascript-with-devtools-16gp</link>
      <guid>https://dev.to/shaur/scopes-in-javascript-with-devtools-16gp</guid>
      <description>&lt;h2&gt;
  
  
  An overview for Scopes in JS with the help of DevTools.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Before we start let's quickly go over some basic terminology.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var&lt;/code&gt; : Use to declare function-scoped /local-scope or globally-scoped variable, optionally initialising it to a value.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt;: The let statement declares a block-scoped local variable, optionally initialising it to a value.&lt;br&gt;
Redeclaration is not possible, but reassignment is possible.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt;: Constants are block-scoped, The value of a constant can't be changed through reassignment, and it can't be redeclared.&lt;br&gt;
However, if a constant is an object or array its properties or items can be updated or removed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;block&lt;/strong&gt;: when we want to treat the multiple lines of code as one aka compound statement we put it in '{}', a block is used with if..else, switch, loops But '{}' used with function is not block scoped but function-scoped.&lt;br&gt;
In strict mode, starting with ES6, functions inside blocks are scoped to that block. Prior to that, block-level functions were forbidden in strict mode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;closure&lt;/strong&gt;: A closure is the combination of a function bundled together with references to its surrounding state (the lexical environment).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: The current context of execution. The context in which values and expressions are "visible" or can be referenced. &lt;/p&gt;




&lt;h3&gt;
  
  
  Scope in Browser DevTools
&lt;/h3&gt;

&lt;p&gt;We will be focusing on &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; and how they are scoped.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Scope in JS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9sh7rt5xiz4xe9bvszu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9sh7rt5xiz4xe9bvszu.png" alt="Types of Scopes"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Showing &lt;strong&gt;Local&lt;/strong&gt;, &lt;strong&gt;Closure&lt;/strong&gt;, &lt;strong&gt;Script&lt;/strong&gt; and &lt;strong&gt;Global&lt;/strong&gt; present in Scope.&lt;/p&gt;




&lt;h3&gt;
  
  
  Global :
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;var&lt;/code&gt; variable declared outside a function, becomes &lt;strong&gt;Global&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Script :
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables declared outside a function or block, goes in &lt;strong&gt;Script&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When JS code Executes, in memory allocation phase &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are given &lt;code&gt;undefined&lt;/code&gt; values.&lt;/p&gt;

&lt;p&gt;The catch is, we can access the &lt;code&gt;var&lt;/code&gt; variable before initialising its value in the code execution part, till then it will give &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; will not behave the same and will give an error (&lt;code&gt;ReferenceError&lt;/code&gt;) and are only accessible once they are defined, this is known as &lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Despite the pros and cons both &lt;strong&gt;Global&lt;/strong&gt;  and &lt;strong&gt;Script&lt;/strong&gt; scope are at the same level i.e., they are present in the &lt;strong&gt;Global Execution Context (GEC)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Script&lt;/strong&gt; and &lt;strong&gt;Global&lt;/strong&gt; scope is always present via &lt;strong&gt;Scope Chaining&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fslyo5pc2ablddcok7coq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fslyo5pc2ablddcok7coq.png" alt="GlobalScope_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declared at Global Scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx947zfe28naxdiodfqa0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx947zfe28naxdiodfqa0.png" alt="GlobalScope_scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;strong&gt;Script&lt;/strong&gt; and &lt;strong&gt;Global&lt;/strong&gt; are created in scope.&lt;/p&gt;




&lt;h3&gt;
  
  
  Functional Scope :
&lt;/h3&gt;

&lt;p&gt;Any variable defined inside a function becomes &lt;strong&gt;Local&lt;/strong&gt; to its function and is not accessible outside. &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; all become &lt;strong&gt;Local&lt;/strong&gt; scoped.&lt;br&gt;
Functions and blocks defined within the function have access to it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4pf75gzskmo51vdbeln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk4pf75gzskmo51vdbeln.png" alt="functionScope_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declared in Function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbse0hrxdjkug0spwa8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbse0hrxdjkug0spwa8p.png" alt="functionScope_scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;strong&gt;Local&lt;/strong&gt; is created in scope for &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Block :
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables defined inside a conditional statement or loops come under &lt;strong&gt;Block&lt;/strong&gt; scope. For &lt;code&gt;var&lt;/code&gt; variables, if a block is defined outside the function&lt;br&gt;
it goes to &lt;strong&gt;Global&lt;/strong&gt; scope and if it's inside a function it goes in the &lt;strong&gt;Local&lt;/strong&gt; scope of the function. Also, if there is any name conflict with &lt;code&gt;var&lt;/code&gt; outside the block, it will overwrite the outside &lt;code&gt;var&lt;/code&gt; value.&lt;br&gt;
&lt;strong&gt;Block&lt;/strong&gt; scope is destroyed once its execution is completed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4izsvvmed1bh1hvs4p7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4izsvvmed1bh1hvs4p7d.png" alt="blockAtGlobal_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declared in Block at Global Scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7sjizbhllm9nlun6lo6t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7sjizbhllm9nlun6lo6t.png" alt="blockAtGlobal_scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;strong&gt;Block&lt;/strong&gt; is created in scope for &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. While &lt;code&gt;var a&lt;/code&gt; overrides the global value.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8et749c88fqz2b30u8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8et749c88fqz2b30u8p.png" alt="blockWithinFunction_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; declared in Block in Function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs19m5ehr0otb89xpdtd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs19m5ehr0otb89xpdtd1.png" alt="blockWithinFunction_scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;strong&gt;Block&lt;/strong&gt; is created in scope for &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. While &lt;code&gt;var&lt;/code&gt; moves in the &lt;strong&gt;Local&lt;/strong&gt; scope of Function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Closure :
&lt;/h3&gt;

&lt;p&gt;It's created for functions and contains the references of values&lt;br&gt;
which are not defined in the function's &lt;strong&gt;Local&lt;/strong&gt; scope or in &lt;strong&gt;Global&lt;/strong&gt; or &lt;strong&gt;Script&lt;/strong&gt;, but are present in the functions in which this function is defined. &lt;br&gt;
It will only form &lt;strong&gt;Closure&lt;/strong&gt; with those values which are used in this function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e0b168us76qoxfmi3df.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e0b168us76qoxfmi3df.png" alt="closureAndHigherOrderFunction_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Function being returned from a Function and forming a &lt;strong&gt;Closure&lt;/strong&gt; in scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmnbwsi4podzea11afvym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmnbwsi4podzea11afvym.png" alt="closureHigherOrderFunction_HigherORderFunctionScope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Scope of Higher Order Fucntion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0p3953mzt6p9em33bst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd0p3953mzt6p9em33bst.png" alt="closureHigherOrderFunction_returnedFunctionScope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Scope of Returned Fucntion, forming &lt;strong&gt;Closure&lt;/strong&gt; with the &lt;strong&gt;Local&lt;/strong&gt; scoped values of Higher Order Fucntion.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mlnujrywgayskhzjhsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2mlnujrywgayskhzjhsu.png" alt="closureNested_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : An Example of 3 level Nested Function forming &lt;strong&gt;Closure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzlw0y48poro375x7yjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftzlw0y48poro375x7yjl.png" alt="closureNested_GarpScope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Scope of grandparent Function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpy22dh76edxtejxco88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpy22dh76edxtejxco88.png" alt="closureNested_dragonScope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Scope of parent Function, Forming forming &lt;strong&gt;Closure&lt;/strong&gt; with grandparent's &lt;strong&gt;Local&lt;/strong&gt; scoped values which are used by it or by its child function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frt1s38wubnqdmpfc456r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frt1s38wubnqdmpfc456r.png" alt="closureNested_lufyScope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Scope of child Function, Forming forming &lt;strong&gt;Closure&lt;/strong&gt; with parent's as well as of grandparent's &lt;strong&gt;Local&lt;/strong&gt; scoped values which are used by it.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivnmbq3xyqqvhir0tip9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fivnmbq3xyqqvhir0tip9.png" alt="closureRefrence_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Example showing &lt;strong&gt;Closure&lt;/strong&gt; is a refrence to the value and not an Actual value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31ph7seiwl9q3u0g9c00.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31ph7seiwl9q3u0g9c00.png" alt="closureRefrence_scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : &lt;strong&gt;Closure&lt;/strong&gt; Formed with grandparent has the new value of &lt;code&gt;var a&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjykwous5g3gzhyrkiozf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjykwous5g3gzhyrkiozf.png" alt="BlockClosure_code"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Higher Order Function with a Block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6k6wsv8xr71aa6xry9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6k6wsv8xr71aa6xry9c.png" alt="BlockClosure_parentScopeBeforeBlock_Scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Parent scope just before block completion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrctxop9fb6eo8phjiab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrctxop9fb6eo8phjiab.png" alt="BlcokClosure_child_Scope"&gt;&lt;/a&gt;&lt;br&gt;
Fig : Child function forming &lt;strong&gt;Closure&lt;/strong&gt; with only &lt;code&gt;var a&lt;/code&gt; from block as it was moved to &lt;strong&gt;Local&lt;/strong&gt; scope of parent and &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; being &lt;strong&gt;Blocked&lt;/strong&gt; scoped were destroyed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Links :
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Header Image :&lt;/strong&gt;  &lt;a href="https://wallpapercave.com/wp/wp2742433.jpg" rel="noopener noreferrer"&gt;https://wallpapercave.com/wp/wp2742433.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repo :&lt;/strong&gt; &lt;a href="https://github.com/Shaur-Repositories/Javascript_Scopes" rel="noopener noreferrer"&gt;https://github.com/Shaur-Repositories/Javascript_Scopes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hosted Page :&lt;/strong&gt; &lt;a href="https://shaur-repositories.github.io/Javascript_Scopes/" rel="noopener noreferrer"&gt;https://shaur-repositories.github.io/Javascript_Scopes/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;I would really appreciate if you can provide your thoughts and feedback in the comments.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hope you find it helpful. Happy coding!
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>devtools</category>
    </item>
  </channel>
</rss>
