Error Duplicate Const Declaration in Switch Case Statement

前端 未结 6 1643
别跟我提以往
别跟我提以往 2020-11-27 05:07

I have the following code and I get the error \'Duplicate Declaration query_url\'.

  switch(condition) {
    case \'complex\':
      const query_url = `somet         


        
6条回答
  •  隐瞒了意图╮
    2020-11-27 05:49

    Just put your switch in a function with some return statements :

    var condition;
    function aSwitch(condition){
    switch(condition) {
        case 'complex':
          return 'something';
        default:
          return 'something';
      }
    }
    const query_url = aSwitch(condition);
    

提交回复
热议问题