DEV Community

biplavmz
biplavmz

Posted on

What is Variable Shadowing in Javascript

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`

Top comments (0)