Making Sense of 'No Shadowed Variable' tslint Warning

后端 未结 7 1534
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 09:58

I have a function that checks for the current stage in a sequential stream, based on a particular discipline that is passed in, and, according to that value, assigns the nex

相关标签:
7条回答
  • 2020-12-10 11:00

    Addording to : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

    ES6 const is BLOCK-SCOPED, thus:


    {
        const TAG='<yourIt>';
        console.log(TAG);
     }
    
     {
      const TAG = '<touchingBase NoImNOt="true">';
      console.log(TAG);
     }
    
     console.log(TAG);  // ERROR expected
    

    AFAICT, this is NOT a case of shadowing - each of the constants is soped correctly within its braces.

    If we cannot re-use variable names, we will wind up with unreadable programs that obscure. rather than inform.

    I believe the warning is wrong-headed

    0 讨论(0)
提交回复
热议问题