why we can't re-declare variable with let in global situation

后端 未结 2 2046
野的像风
野的像风 2021-01-29 15:53

When I declare a variable using the let keyword that is already declared using the let keyword in the same scope, then it throws a SyntaxError exception. Consider this example:<

2条回答
  •  执笔经年
    2021-01-29 16:37

    Let and Const Declarations will throw an error if you redeclare them in the same scope. However, they follow different rules in that their declarations aren't hoisted and their scope is limited to the first set of containing curly braces.

    Reference: https://www.quora.com/What-does-happen-if-we-re-declare-a-variable-in-JavaScript

提交回复
热议问题