Logo
HTMLCSSJavaScriptReactjsnewResourcesContactUpdates
Join

Get started today

HTMLCSSJavaScriptReactjsnewResourcesContactUpdates

Tools

Resume BuilderQR GeneratorVS Code Editor

Connect

GitHubWhatsApp Channel
practice questions
closure

Lexical scope/Scope Chain

By Saket Bhatnagar•December 16, 2025•Beginner to Intermediate

Table of Contents

  1. lexical scope/Scope chain

lexical scope/Scope chain

  1. 1The ability of js engine to search for a variable in the outer scope when variable is not available in local scope is known as

    lexical scope or scope chain.

  2. 2It is ability of child to access variable from outside if its not present in local scope
  3. 3 Lexical scope : A function and global object.
    1let a = 10;
    2function test() {
    3 a++;
    4 console.log( a );
    5}
    6test();
    7
    8Output : 11

    When test function is executed js engine looks for ' a ' in local scope. Since it will not available it will look for a in outer scope that is global window object .
  4. 4Lexical scope : The child function and parent function with a help of closure.
    1function outer() {
    2 let a = 10;
    3 function inner() {
    4 console.log(a);
    5 }
    6 return inner;
    7}
    8
    9let res = outer();
    10res();
    11
    12Output : 10

    When the function inner is executed and console.log a is encountered, js engine looks for a in the local scope of function inner.
    Since, a is not present and function inner is child of function outer js engine will search for a in the parent function outer scope with the help of closure.

Share this article

Last updated: January 16, 2026

Saket Bhatnagar

I build products, share the playbooks, and pass along everything I learn so you can ship faster.

GitHubLinkedInYouTubeWhatsApp Channel

Quick Links

  • Updates
  • Resources
  • Resume Builder
  • Contact

WhatsApp

Builders Group

Real-time notes from my builds, weekend challenges, and accountability threads.

Shipping Notes Channel

Launch alerts + bite-sized lessons.

© 2025 Saket Bhatnagar. All rights reserved.

Always building, always learning.