<?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: Vishal Heble</title>
    <description>The latest articles on DEV Community by Vishal Heble (@heblev).</description>
    <link>https://dev.to/heblev</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%2F407762%2F06ce3f93-a35b-4a21-8cb1-8adb7d87c2ee.jpg</url>
      <title>DEV Community: Vishal Heble</title>
      <link>https://dev.to/heblev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/heblev"/>
    <language>en</language>
    <item>
      <title>What is a SCOPE in javascript ?</title>
      <dc:creator>Vishal Heble</dc:creator>
      <pubDate>Sat, 13 Jun 2020 21:49:14 +0000</pubDate>
      <link>https://dev.to/heblev/what-is-a-scope-in-javascript-55o5</link>
      <guid>https://dev.to/heblev/what-is-a-scope-in-javascript-55o5</guid>
      <description>&lt;p&gt;Scope is the &lt;b&gt;execution context area&lt;/b&gt; and the ability to access a variable based on how you declare them. One important difference between JavaScript and other languages mostly C-based languages is Variables are created at the spot(execution context area) where they are declared in latter case. &lt;b&gt;But in JS, the variables are created in a spot depending on how you declare them&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;There are 2 types of scopes :&lt;/p&gt;

&lt;p&gt;&lt;b&gt;1) Global Scope&lt;/b&gt;&lt;br&gt;
The area outside function is considered a global scope (window). So a variable can be accessed in other scopes (functions/blocks) as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sZvNHTqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yn613zpkqct7hfhkw22m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sZvNHTqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yn613zpkqct7hfhkw22m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;2) Local Scope&lt;/b&gt;&lt;br&gt;
It has 3 different types :&lt;/p&gt;

&lt;p&gt;&lt;b&gt;a) Function Scope&lt;/b&gt;&lt;br&gt;
When you declare a variable inside a function, it is accessible within function only.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4-PCT2qF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2r8wl9w5q4wyhn3x4rkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4-PCT2qF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2r8wl9w5q4wyhn3x4rkg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; This is same for let and const as well.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;b) Block Scope&lt;/b&gt;&lt;br&gt;
In ES6, &lt;b&gt;let&lt;/b&gt; and &lt;b&gt;const&lt;/b&gt; allow to declare variables in a block scope where in the variable is accessible only within the curly braces { } or a block like for and while loops, if and switch conditions etc. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FPhc6E4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd1dddnnh495b8uh2uh3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FPhc6E4m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd1dddnnh495b8uh2uh3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;c) Lexical Scope&lt;/b&gt;&lt;br&gt;
The child scope have access to the variables defined in its parent scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--34-7V0-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gj5ipyk1bdvvq3t4q6ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--34-7V0-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gj5ipyk1bdvvq3t4q6ui.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
