var let可以,但是let可以吗? [英] var let is ok but let let isn't?
问题描述
//Version A:
var let = true;
console.log(let);//true
//Version B:
let let = 0; //syntax Error: let is disallowed as a lexically bound name
console.log(let);
是否有特定的原因允许我们使用var
创建的名称为let
的变量,但不允许使用let
?通过此实验,是否还意味着变量名称let
可以存在于全局级别,但不能存在于某些范围级别?但是不是全球性的考虑范围吗?
Is there any particular reason where we allow variable with name let
created using var
but not let
? With this experiment, is that also means that variable name let
is ok to exist on global level but not in some scope level? But isn't global is consider scope?
推荐答案
因为规范如此.
来自
LexicalDeclaration LexicalDeclaration 变量声明规范没有这样的限制,可能是因为在定义 The variable statement specification has no such limitation, probably because 这篇关于var let可以,但是let可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 13.3.1允许和禁止声明
13.3.1.1静态语义:早期错误
:
LetOrConst BindingList ;
13.3.1 Let and Const Declarations
13.3.1.1 Static Semantics: Early Errors
:
LetOrConst BindingList ;
"let"
,则是语法错误.
"let"
.var
时未使用let
,并且更改var
的规范将是一个重大更改.let
was not in use at the time var
was defined, and changing the specification for var
would be a breaking change.