Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1.34 KB

File metadata and controls

27 lines (20 loc) · 1.34 KB

Scopes.

Scopes in javascript refers to the current context of code, which determines the accessibilty of variables to javascript. Javascript has the following kinds of scopes:-

  • Global Scope
  • Module Scope
  • Function Scope
  • Block Scope
  • Lexical Scope

Global Scope :-

Variables defined outside any function, block, or module scope have everywhere in the application. when a module system is enabled it's harder to make global variables,but one can still do it. By defining a variable in HTML, outside any function, a global variable can be created.

Module Scope :-

Before modules, a variable declared outside any function was a global variable. In modules, a variable declared outside any function is hidden and not available to other modules unless it is explicity exported..

Block Scope :-

Block scope is defined with curly braces. it is separated by { and }. Variables declared with let and const can have block scope. They can only be accessed in the block in which they are defined.

Function Scope :-

Function scope means that parameters and variables defined in a function are visible everywhere within the function, but are not visible outside of the function.

Lexical Scope :-

Lexical scope is tha ability of the inner function to access the outer scope in which is defined.

For More Information Click Below :-

Scopes