I'm trying use switch statement to perform a task. I have declared a variable using let in first case. But when i try to access it in second case it says "Uncaught ReferenceError: t is not defined"
x = "20";
switch (x) {
case '10':
let t = 15;
break;
case '20':
console.log(t);
}
I get this error
Uncaught ReferenceError: t is not defined at :6:21
but if i try to declare same variable in second case then
x = "20";
switch (x) {
case '10':
let t = 15;
break;
case '20':
let t = 150;
console.log(t);
}
i get this error
Uncaught SyntaxError: Identifier 't' has already been declared
why is this happening? how to solve this issue without using var and without declaring variable with different name. Thanks in Advance.