官网的解释:The reason is that the lexical declaration is visible in the entire switch block but it only gets initialized when it is assigned, which will only happen if the case where it is defined is reached.
没怎么看懂
官网的解释:The reason is that the lexical declaration is visible in the entire switch block but it only gets initialized when it is assigned, which will only happen if the case where it is defined is reached.
没怎么看懂
8 回答5.1k 阅读✓ 已解决
6 回答3.3k 阅读✓ 已解决
6 回答3.9k 阅读✓ 已解决
5 回答3.1k 阅读✓ 已解决
9 回答3.1k 阅读
6 回答2.7k 阅读
5 回答6.7k 阅读✓ 已解决
有中文网站 no-case-declarations
大概是指上面
case 1
里的x
在case 2
里也会生效,所以要用{}
包起来,防止x
提升到整个switch
语句。