Why does re-declaring an argument inside of a try/catch throw a ReferenceError?

后端 未结 4 649
北恋
北恋 2020-12-28 13:20

I mistakenly wrote a re-declaration of an argument as a const in a function and instead of throwing SyntaxError: Identifier \'bar\' has already been decla

4条回答
  •  爱一瞬间的悲伤
    2020-12-28 14:10

    Taken from here https://tylermcginnis.com/videos/var-let-const/

    var is function scoped and if you try to use a variable declared with var before the actual declaration, you'll just get undefined. const and let are blocked scoped and if you try to use a const or let variable before the declaration you'll get a reference error.

提交回复
热议问题