{"componentChunkName":"component---src-templates-blog-post-js","path":"/execution-context-lexical-environmenet-scope-chain","result":{"data":{"markdownRemark":{"id":"6ad00ece-8ecb-51cb-8b1e-8c743dd59998","html":"<!--StartFragment-->\n<p>Hey guys,</p>\n<p>So execution context, lexical scope, and scope chain are sort of fundamental topics in JS so it's important to learn about it</p>\n<p>Let's get started</p>\n<h2><strong>Execution Context</strong></h2>\n<p>Now we know about the call stack (if you don't please refer to the last blog post <a href=\"https://www.aviatecoders.com/how-javascript-works\">here</a>) and we know that functions that are called goes onto the call stack and after returning the functions they are popped off the call stack and it gets empty</p>\n<p><em>We can say that every function that goes into the call stack has its execution context</em></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token string\">\"Hey guys\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greetings</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">greetings</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Let's see this with an example</p>\n<p>So in the above example when the JS engine encounters the function call greetings( ) it makes an execution context of that function and puts it onto the call stack and after that, it encounters hello( ) and makes its execution context and puts it onto the stack and finally, it returns \"Hey Guys\" and everything pops off one by one.</p>\n<p><strong>A new execution context is created whenever a function is executed as the JS engine goes through the code</strong></p>\n<p><figure class=\"gatsby-resp-image-figure\" style=\"\">\n    <span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1024px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 54.296875%; position: relative; bottom: 0; left: 0; background-image: url('data:image/svg+xml,%3csvg%20xmlns=\\'http://www.w3.org/2000/svg\\'%20width=\\'400\\'%20height=\\'218\\'%20viewBox=\\'0%200%20400%20218\\'%20preserveAspectRatio=\\'none\\'%3e%3cpath%20d=\\'M0%20109v109h401V0H0v109m296-91c-26%203-46%2012-61%2027-6%205-7%206-9%205l-2-1-2%2015%207-3c7-4%207-4%205-6l-2-2%205-5c20-20%2047-28%2087-27h18l-2-2c-4-2-36-2-44-1M172%2095c-6%200-7%201-7%2011-1%2014-4%2013%2038%2013s39%201%2039-13c0-13%203-12-34-12l-36%201m83%200c-7%200-8%201-8%2012%200%2013-3%2012%2038%2012l37-1c3-2%203-21%200-23h-67\\'%20fill=\\'%23d3d3d3\\'%20fill-rule=\\'evenodd\\'/%3e%3c/svg%3e'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Execution Context\"\n        title=\"Execution Context\"\n        src=\"/static/a0aeadd4003a16bbf47ce314a41687dd/2bef9/execution-context.png\"\n        srcset=\"/static/a0aeadd4003a16bbf47ce314a41687dd/6f3f2/execution-context.png 256w,\n/static/a0aeadd4003a16bbf47ce314a41687dd/01e7c/execution-context.png 512w,\n/static/a0aeadd4003a16bbf47ce314a41687dd/2bef9/execution-context.png 1024w,\n/static/a0aeadd4003a16bbf47ce314a41687dd/71c1d/execution-context.png 1536w,\n/static/a0aeadd4003a16bbf47ce314a41687dd/2e06c/execution-context.png 1637w\"\n        sizes=\"(max-width: 1024px) 100vw, 1024px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span>\n    <figcaption class=\"gatsby-resp-image-figcaption\">Execution Context</figcaption>\n  </figure></p>\n<p>But always the very first execution context is the \"Global Execution Context\" which is defined even before any code is written in the JS file</p>\n<p>The Global execution context has the global object which is the window object, the \"this\" keyword, and hoisting.</p>\n<p>It has two phases the creation phase and the execution phase</p>\n<p>In the creation phase, there is the window object, \"this\" keyword, and hoisting and</p>\n<p>In the execution phase, the code is run</p>\n<p>As you might know at the beginning the \"this\" keyword and the window object are the same</p>\n<p><figure class=\"gatsby-resp-image-figure\" style=\"\">\n    <span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1024px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 54.296875%; position: relative; bottom: 0; left: 0; background-image: url('data:image/svg+xml,%3csvg%20xmlns=\\'http://www.w3.org/2000/svg\\'%20width=\\'400\\'%20height=\\'217\\'%20viewBox=\\'0%200%20400%20217\\'%20preserveAspectRatio=\\'none\\'%3e%3cpath%20d=\\'M0%20109v108h401V0H0v109M182%207l-6%203-5-3c-5-3-5-3-5-1l1%205c2%203%202%203-1%205l-4%202-2%205c0%205%201%206%2016%2014l10%206%2011-7%2014-8c3-1%203-2%203-6v-5l-12-7-13-7-7%204m113%2018c-28%203-44%209-58%2021-5%205-6%206-7%204-3-1-3%200-4%206l-2%206v3l7-4c7-3%207-3%205-5-1-2-1-2%203-6%2017-15%2037-21%2066-21%2014%200%2029%201%2034%203%202%200%203-3%201-4-2-2-37-4-45-3M84%2093l-7%201v25c2%203%2084%203%2086%200s1-24%200-25c-2-1-66-2-79-1m98%200c-5%200-6%202-6%2015%200%2011%200%2012%202%2013l34%201h33l1-2c1-2%202-6%202-13%200-16%203-15-34-15l-32%201M79%20184v24c2%202%20252%203%20254%200v-22l-1-3H206l-127%201m148%209c-2%202-1%207%201%207h13l3%201c3%200%203%200%203-4s0-5-2-5l-1%201-1%201-2%202h-2c-2-3-2-2-6%201-3%204-5%203-5%200s3-5%203-3l1%201c2-1%200-3-2-3l-3%201\\'%20fill=\\'%23d3d3d3\\'%20fill-rule=\\'evenodd\\'/%3e%3c/svg%3e'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Global Execution Context\"\n        title=\"Global Execution Context\"\n        src=\"/static/28e373c787a74ba99c8ef274b1d7be1e/2bef9/global-execution-context.png\"\n        srcset=\"/static/28e373c787a74ba99c8ef274b1d7be1e/6f3f2/global-execution-context.png 256w,\n/static/28e373c787a74ba99c8ef274b1d7be1e/01e7c/global-execution-context.png 512w,\n/static/28e373c787a74ba99c8ef274b1d7be1e/2bef9/global-execution-context.png 1024w,\n/static/28e373c787a74ba99c8ef274b1d7be1e/71c1d/global-execution-context.png 1536w,\n/static/28e373c787a74ba99c8ef274b1d7be1e/6ee58/global-execution-context.png 1640w\"\n        sizes=\"(max-width: 1024px) 100vw, 1024px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span>\n    <figcaption class=\"gatsby-resp-image-figcaption\">Global Execution Context</figcaption>\n  </figure></p>\n<h2><strong>Lexical Environment</strong></h2>\n<p>Before going into the lexical environment, let's understand what lexical means well it means where you write something or define something</p>\n<p>So, as we know that when our program is run we have execution context of functions on the call stack and you can understand the lexical environment as each function has its planet where its variable is located and no one outside of the planet can use those variables</p>\n<p>Let's understand this with an example</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hell\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"greet\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token number\">20</span>\n <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"starting greet\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> d <span class=\"token operator\">=</span> <span class=\"token number\">40</span>\n\n<span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Here as you can see when the start() function is called, it starts execution each function one by one, now if you want to see this in action please go to this (<a href=\"http://latentflip.com/loupe/?code=JC5vbignYnV0dG9uJywgJ2NsaWNrJywgZnVuY3Rpb24gb25DbGljaygpIHsKICAgIHNldFRpbWVvdXQoZnVuY3Rpb24gdGltZXIoKSB7CiAgICAgICAgY29uc29sZS5sb2coJ1lvdSBjbGlja2VkIHRoZSBidXR0b24hJyk7ICAgIAogICAgfSwgMjAwMCk7Cn0pOwoKY29uc29sZS5sb2coIkhpISIpOwoKc2V0VGltZW91dChmdW5jdGlvbiB0aW1lb3V0KCkgewogICAgY29uc29sZS5sb2coIkNsaWNrIHRoZSBidXR0b24hIik7Cn0sIDUwMDApOwoKY29uc29sZS5sb2coIldlbGNvbWUgdG8gbG91cGUuIik7!!!PGJ1dHRvbj5DbGljayBtZSE8L2J1dHRvbj4%3D\">latentflip</a>) website and copy-paste the code</p>\n<p>So as you can see the hello function has variable a but the function hello doesn't have access to other variables like the variable b or c because they on another function but it does have access to variable d because it's on the global scope or environment</p>\n<p>Similar is the case with variable b or c because they are both inside their respective functions and only have access to their variables and that's what lexical environment means</p>\n<p>That's why I said to image each function that goes onto the call stack and an execution context is created and it has its planet as well and no one other the function itself can access that planets variables</p>\n<p><figure class=\"gatsby-resp-image-figure\" style=\"\">\n    <span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 498px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 79.296875%; position: relative; bottom: 0; left: 0; background-image: url('data:image/svg+xml,%3csvg%20xmlns=\\'http://www.w3.org/2000/svg\\'%20width=\\'400\\'%20height=\\'316\\'%20viewBox=\\'0%200%20400%20316\\'%20preserveAspectRatio=\\'none\\'%3e%3cpath%20d=\\'M18%20124l1%2089h67a1564%201564%200%200166%201l74-1h71v-22h3c3%201%205-1%203-2h-1l-2%201h-3v-42h2l3%201h2l-1-3h-1l-2%201h-3v-40h2l3%201h2l-1-3h-1l-2%201h-3V71a423%20423%200%2000-3%2036c3%201%203%2039%200%2040v1c3%202%202%2042%200%2041l-1%201%202%201%201%2010v11H20v-89a1426%201426%200%2000-2%201m27-38l-1%203H24v36h266V89H45l1-3v-3l-1%203m273%205c-13%207-13%2025%200%2031%207%203%2014%202%2019-3%2015-13-1-37-19-28M24%20147v18h266v-36H24v18m294-15c-5%203-7%206-9%2012-4%2016%2017%2028%2029%2016%2013-14-2-37-20-28M25%20170l-1%2018v17h266v-35l-133-1-132%201m293%203c-14%207-12%2028%203%2032l4%201v15l1%2015v-30l3-1%208-3c15-13%200-38-19-29\\'%20fill=\\'%23d3d3d3\\'%20fill-rule=\\'evenodd\\'/%3e%3c/svg%3e'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Lexical Environment\"\n        title=\"Lexical Environment\"\n        src=\"/static/a63702e3a328cf0673b688e9e17f0d4f/79e1b/lexical-environment.png\"\n        srcset=\"/static/a63702e3a328cf0673b688e9e17f0d4f/6f3f2/lexical-environment.png 256w,\n/static/a63702e3a328cf0673b688e9e17f0d4f/79e1b/lexical-environment.png 498w\"\n        sizes=\"(max-width: 498px) 100vw, 498px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span>\n    <figcaption class=\"gatsby-resp-image-figcaption\">Lexical Environment</figcaption>\n  </figure></p>\n<p>The same thing can be done with the functions as well we can define functions inside of each other and stuff like that which we are going to cover in the scope chain</p>\n<p>So just remember that when we say lexical environment it just means where is that variable or function written in our code</p>\n<h2><strong>Scope chain</strong></h2>\n<p>Let's see and learn about what scope chain is</p>\n<p>What it does is that when the Js engine first parses through the code it just links functions and variables around it on where they are written</p>\n<p>Now how it does that well depends majorly on where the function is defined so if the function is defined like this eg</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hell\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"greet\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"starting greet\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now as you can see in this example the functions are defined on the main body of the program that means they are linked or their execution context is linked directly to the global execution context</p>\n<p>So that means where ever if we define a variable in the global execution context every function will have the access to it</p>\n<p>Every function is individually linked to the global execution context</p>\n<p>But in this example</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hell\"</span><span class=\"token punctuation\">)</span>\n <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">;</span>\n <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span> \n <span class=\"token keyword\">var</span> b <span class=\"token operator\">=</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">;</span>\n <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">var</span> c <span class=\"token operator\">=</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token string\">\"Ok\"</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// this will invoke function hello()</span>\n<span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// this will invoke function greet()</span>\n<span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// this will return Ok</span></code></pre></div>\n<p>As you can see in the above example we are defining the function one inside the another and that means the scope chains of the functions will be linked to each other, and that is the most important thing to understand in the scope chain</p>\n<p>Here you can also understand each function as an individual planet</p>\n<p>— So the bigger planet global has the planet start inside of it and the planet start will have hello inside of it and finally, we will have planet greet inside of it</p>\n<p>Always remember that the planet greet which is inside of everybody will have access to every variable but no one has access to the variables of greet</p>\n<p>For the planet hello it will have access to every variable except for greet's variable environment</p>\n<p>For the planet start it will have access to the global variables but not the planet's inside of it</p>\n<p>For more explanation:-</p>\n<ol>\n<li>Let me explain how these functions are linked to each other - so the last function or the last child named greet( ) will have access to both var a and var b because they are their parent</li>\n<li>Now for hello( ) it has access to var a but it doesn't have the connection with greet( ) which is variable c so if you try to console.log(c) then it will throw a reference error</li>\n<li>For a start( ) it only has access to var its variable but not b or c and similarly it will give a reference error if we try to access those</li>\n</ol>\n<p>But the common thing is that every function has access to the global scope and its variables</p>\n<p>That's what scope chain is in Javascript</p>\n<p>Before I leave here is an important difference between functional and block scope which I guess you should also know</p>\n<p>Function scope and block scope</p>\n<p>Initially, Js could only use function scoping as we have studied before and most of the other programming languages have block scoping</p>\n<p>eg</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">></span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">var</span> secret <span class=\"token operator\">=</span> <span class=\"token string\">\"555\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">secret</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">var</span> secret2 <span class=\"token operator\">=</span> <span class=\"token string\">\"555\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">//In javascript we can access the secret variable from here like outside of the if statement</span>\n<span class=\"token comment\">//but we can't access secret2 and thats why Js is called function scoped</span>\n\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secret<span class=\"token punctuation\">)</span> <span class=\"token comment\">// \"555\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secret2<span class=\"token punctuation\">)</span> <span class=\"token comment\">// reference error</span>\n\n<span class=\"token comment\">// But in many other programming languages we can't access that the secret variable </span>\n<span class=\"token comment\">// because they are block scoped</span></code></pre></div>\n<p>But if we use let and const instead of var in the If statement then Js will also be able to use block scoping and we won't be able to access the variable secret from outside of the if statement</p>\n<p>Well these are concepts and theory of execution context, lexical scope, and scope chain, I hope you enjoyed learning it and understanding the stuff</p>\n<p>Was the article helpful? Do you have any doubts? Any topic you would like us to cover?</p>\n<p>Reach out to us on <a href=\"https://twitter.com/aviatecoders\">Twitter</a> and <a href=\"https://instagram.com/aviatecoders\">Instagram</a> where we try to provide more value in threads and carousal formats</p>\n<p>Thank You for your time</p>\n<p>Keep learning, Keep coding :)</p>\n<!--EndFragment-->","excerpt":"Hey guys, So execution context, lexical scope, and scope chain are sort of fundamental topics in JS so it's important to learn about it Let's get…","frontmatter":{"date":"April 08, 2021","slug":"/execution-context-lexical-environmenet-scope-chain","title":"Execution Context, Lexical Environment and Scope chain","description":"Understand the most core of Javascript about execution context, lexical environment, and scope chain ","featuredImage":{"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC4ElEQVQozzWTy28bVRTGz70zTuKxnTqO4zgPx3GIQ+JHOokTK81LeZU8XDsmmDSuo0AJVUFVRFQKAoF4qghEpbJgBYtKLFB33ZQFEuwrJNixYgOb/gPddFP9OEFicXTvjGZ+Ot93viPGFjCmSMD4eDJD1JRJyAUGzRLPySo58wK+2aZsqlwwdea15qTOlFQ4sl9yJ/gbN0I/8VbPQz48eYoYm8eaSdpkmrDMElNYnyySNiuMyUVysoMvVWZljyVpsN5xwLJtcNV8yl33Z9537tMKfMdHyb+ZH/tTge4kIudxbJl2u0DYLhNz1+iSTZYza/x6L8ej+3ke/Vikka5QVnAzfIt3ne+5bu5w5NzmNPiAVe8H/f8S4sUvYtwy0raoD+tIaBPn3A7i1pgrb/DscYp/fk/yxy+9HPobLMoxTec96t4pW/aElvMF9bZPeN5pqVLluMkqwZ4q0rmBdG0heneSNSTyEuXVHZ781c+9bzr5+uMwVwpVBV5nwe5TsruseNeYc66RN02GA/t4IW3EDFQwiQYm2UCiCuyuKLSOxPZJZCu8dliidcnneLvMYrTOhPqZVW9H1ZK0bDDUXqFXavQ5VaLxbcQOqO5EHdvbJDr+KsGhfSJjrxMaPiTYf6A2HBFxDnTqLXLeHrnIDhORCmOdW6S9NQYjqwxrA33eLuHYpgJjSu3Zw3Y3GJl9m8zKZ4wu3GKgeMzg5A2K5RPmSm/gZy4zO3IZP7VHQW2aGW3gj7zI+WydQnaXgUSN9nOq0ARKOgiV2X0FSd5E+k/11HviSN81CcV3KRZfIRWv0KmRimi0wlIiKFO0azpcKWpKJrAyide1fpbDcZ3MskI+wGZuq59vYlM3CWZOSeeukp1QuakahfGXGU1V8MwMQVOiw05rTKYIWB/XnkUvjzgFBTpLSPgdpPdblf450vcVMnQXGz/G7ZjXD2Z0k6Yx4uNouWenLoLV7fq/jDkD5f/r9F+Va1OJf7efIgAAAABJRU5ErkJggg==","aspectRatio":1.7412935323383085,"src":"/static/8d7e2f1b33ddce39c714a8c755ec9fb8/03979/cover-image-execution-context.png","srcSet":"/static/8d7e2f1b33ddce39c714a8c755ec9fb8/6cdeb/cover-image-execution-context.png 350w,\n/static/8d7e2f1b33ddce39c714a8c755ec9fb8/b1dd8/cover-image-execution-context.png 700w,\n/static/8d7e2f1b33ddce39c714a8c755ec9fb8/03979/cover-image-execution-context.png 800w,\n/static/8d7e2f1b33ddce39c714a8c755ec9fb8/1783d/cover-image-execution-context.png 1050w,\n/static/8d7e2f1b33ddce39c714a8c755ec9fb8/942ca/cover-image-execution-context.png 1400w,\n/static/8d7e2f1b33ddce39c714a8c755ec9fb8/b5274/cover-image-execution-context.png 3000w","sizes":"(max-width: 800px) 100vw, 800px","maxHeight":459,"maxWidth":800},"sizes":{"src":"/static/8d7e2f1b33ddce39c714a8c755ec9fb8/ee604/cover-image-execution-context.png"}}}}}},"pageContext":{"id":"6ad00ece-8ecb-51cb-8b1e-8c743dd59998","previous":{"id":"61811465-56e5-5327-be6c-9f56efe6ff5b","frontmatter":{"slug":"/how-javascript-works","template":"blog-post","title":"How Javascript works?"}},"next":{"id":"32bfe0f7-810a-5b97-b196-7215a5b03ade","frontmatter":{"slug":"/what-is-hoisting-in-javascript","template":"blog-post","title":"Hoisting in Javascript"}}}},"staticQueryHashes":["228695001","3868140423"]}