Open
Description
Please type "I already searched for this issue":
I already searched for this issue.
Edition: (1st or 2nd)
2nd
Book Title:
Scope & Closures
Chapter:
Chapter 6: Limiting Scope Exposure
Section Title:
Scoping with Blocks
Problem:
The
{ .. }
curly-brace pair on aswitch
statement (around the set ofcase
clauses) does not define a block/scope.
As best I can tell, the switch statement curly-braces referred to do create a scope with const
or let
.
For example, with var
, foo outputs 'foo'
as expected.
switch (true) {
case true:
var foo = 'foo';
}
console.log(foo);
However, with let
, logging foo
produces a reference error. (Not expected if these braces aren't creating a scope)
switch (true) {
case true:
let foo = 'foo';
}
console.log(foo);
This came up in our last online Code Club discussion (which I believe you have visited previously). Thanks so much for providing this resource!