Explain Different Types of Scopes in JavaScript ?

Scope refers to the environment in which a variable or a function is declared and accessible. It means the environment in which the variable is visible, can be accessed and changes can be made to it. It is of three types in JavaScript.

  • Functional Scope: This scope is mainly contained by the variables that are declared inside a function. These variables can only be accessed inside the function not outside of that.
  • Global Scope: It is the global scope, which means a variable or function created in this scope can be accessed anywhere in the code.
  • Block Scope: It was introduced in ES6 with the introduction of the let and const variables. In this scope, if a variable is created inside a block of code or curly brackets ({}), it will not be accessible outside that block.

Contact Us