Why does var allow duplicate declaration but why does const and let not allow duplicate declaration?

前端 未结 4 610
余生分开走
余生分开走 2021-01-06 16:52

Why does var allow duplicate declaration but why does const and let not allow duplicate declaration?

var is allow duplicate declaration

4条回答
  •  遥遥无期
    2021-01-06 17:25

    Unlike var, let is an ES2015 specification. The specification says:

    Redeclaring the same variable within the same function or block scope raises a SyntaxError.

    This is to improve scoping over vanilla var.

提交回复
热议问题