For the curious, this was in part to provide data for a conversation on a project about switch statements versus multiple "if" statements. Turns out variable scoping in case statements is not generally well understood. Only half saw an error. IMO "switch" is a trap.https://twitter.com/HenrikJoreteg/status/1222273872046616576 …
The "const" in the first case is not scoped to just that case statement. So the first const is already available in the second case.
Solutions:
1. Add curly statements to case to create a block scope (lint rules exist for this).
2. Don't use switch (aka, the Python solution
)
-
-
Also case fall through is a huge foot gun (obviously not the case here since you return). Though in some cases I prefer switch over ifs, but can't articulate why
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.