The curly braces used in this way set their own block area, in which you can define local let variables or const :
switch (false) { case true: { let x = "bar"; console.log(x); break; } case false: { let x = "baz"; console.log(x); break; } }
The example will be thrown without nested blocks, since multiple let / const declarations with the same identifier are not allowed within the same scope in Ecmascript 2015.
Note that the switch creates the scale of the block itself, that is, regardless of whether you use nested areas of the block or not, let / const declarations inside the switch do not leak into the parent area.
However, in the context of a switch curly braces are also used exclusively decoratively to visually highlight blocks of individual case branches.
source share