Illegal Shadowing Javascript
- What is illegal shadowing?
- We can shadow
varvariable bylet, but we cannot shadowletvariable byvar - Shadowing
letvariable byvaris called illegal shadowing
- We can shadow
function test() {
let a = "Hello";
let b = "Bye";
if (true) {
let a = "Hi"; // Successful shadowing
// Illegal Shadowing
var b = "Goodbye"; // SyntaxError: 'b' has already been declared
console.log(a);
console.log(b);
}
}
test();