scope and lexical scope in javaScript || lexical scope in javascript in Hindi

Опубликовано: 24 Январь 2026
на канале: Code With Fun
100
6

In JavaScript, the scope chain and lexical scope are closely related concepts that determine how variables are resolved and accessed in nested functions. Understanding these concepts is crucial for understanding variable scoping in JavaScript.

Scope Chain:
The scope chain is a mechanism used by JavaScript to look up variables in nested functions. When a variable is accessed within a function, JavaScript searches for that variable in the current function's scope. If the variable is not found, it continues the search in the next outer scope until it reaches the global scope

Lexical Scope:
Lexical scope, also known as static scope, is based on the physical structure of your code. It allows variables and functions to be accessed by nested functions based on where they are defined in the code, rather than where they are called. Variables declared with the let and const keywords (introduced in ES6) have lexical scope.