I am glad JavaScript has the new let statement to declare a block scope local variable. However, there appears to be a type error when declaring to let
variables in a switch statement, which would be a very useful scenario to use let
.
function test(x) {
'use strict';
switch (x) {
case 0:
let foo;
break;
case 1:
let foo; // TypeError for redeclaration.
break;
}
}
Sure enough, MDN shows this example:
You may encounter errors in switch statements because there is only one underlying block.
So why is a switch statement only one underlying block?