What do the curly braces do in switch statement after case in es6?

前端 未结 2 1410
天涯浪人
天涯浪人 2020-12-30 19:21

What\'s the difference between:

switch (expression) {
    case:
      somethings;
      break;
}

and

switch (expression) {
         


        
2条回答
  •  离开以前
    2020-12-30 20:00

    you have to use curly brackets:

    1. when creating more block scoped variables (const / let) with the same name
      • according to spec MDN web docs
      • ERROR: Uncaught SyntaxError: Identifier 'variablename' has already been declared
    2. when using eslint in default settings and using even single one (const / let)
      • according to rule no-case-declarations
      • ERROR: Unexpected lexical declaration in case block no-case-declarations

提交回复
热议问题