What is Variable Shadowing in Javascript
biplavmz
Posted on April 30, 2024
when variable Shadowing occur in which condition
Variable Shadowing occurs when a variable Declare with a local Scope (such as in function or block level Scope)
has the same name as a variable in the outerScope.
as the result inner variable shadow the outer variable
it will work for all (var,let,const)
`var x = 10;;
function m1(){
var x = 100; // inner variable will shadow the outer variable
console.log(x);
}
m1(); // it will print 100;
console.log(x); // it will print 10`
đź’– đź’Ş đź™… đźš©
biplavmz
Posted on April 30, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
react Everything You Need to Know About React useState Hook – Practical Examples Inside
September 30, 2024