DEV Community

biplavmz
biplavmz

Posted on

1

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)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay