Logo
HTMLCSSJavaScriptReactjsnewContactUpdates

Get started today

HTMLCSSJavaScriptReactjsnewContactUpdates

Tools

Resume BuilderQR GeneratorVS Code Editor

Connect

GitHubWhatsApp Channel
token
global execution context

Javascript Scopes

By Saket Bhatnagar•June 14, 2025•Beginner to Intermediate

Table of Contents

  1. scope
  2. We have Two scopes
  3. Global scope
  4. Local scope

scope

  1. 1Scope defines the visibility or accessibility of a variable.

We have Two scopes

  1. 1Global Scope
  2. 2Local Scope

Global scope

  1. 1The variable declared in global scope can be accessed anywhere in the program.
  2. 2Global scope has the highest accessibility.
  3. 3Variable declared with var goes in Global scope.

Local scope

  1. 1Local/block scope/function scope
  2. 2The variable declared in local scope can be accessed in that block only i.e. we can not access the variable from outside.
  3. 3JS engine creates local scope for functions and blocks.
  4. 4

    Function's Local Scope

    - Local scope created for function is refered as function scope.
    - Variable's declared in function's scope can not be accessed from outside.
  5. 5

    Block's Local Scope

    - Local scope created for block is refered as block scope.
    - Variable's declared in block scope can not be accessed from outside.
    - But only variables declared with var are accessible from outside of block.

    Note: Variables declared with let and const are also locally scoped.
    Firefox represent it as - Block scope.
    Chrome represent it as - Script scope.

Share this article

Last updated: July 14, 2025

Join Our Community

Login to Join

© 2025 Saket Bhatnagar. All rights reserved.

    ☕