Lexical Scope
The variable is declared inside the function and can only be accessed inside that block or nested block is called lexical scope.
Example: In this example, we will declare the variable inside the function and going to access inside the nested function.
Javascript
function outerFunction() { const outerVariable = "Hello" ; function innerFunction() { const innerVariable = "Geeks" ; console.log(`${outerVariable} ${innerVariable}`); } innerFunction(); } outerFunction(); |
Output:
Hello Geeks
Javascript Scope
JavaScript Scope is the area where a variable (or function) exists and is accessible. We can layer the scope in a system which means the child scope can access the parent scope but not vice-versa.
Contact Us