In es6, variables declared by let cannot have the same name, because let does not allow the same variable to be declared repeatedly in the same scope, otherwise an error will occur; therefore, let can be used to prevent duplication of variable naming, and Prevent variable pollution; the opposite of let is var, which allows repeated declaration of variables.
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
The let declaration in es6 cannot have the same name
let is not allowed to be declared repeatedly in the same scope same variable. Otherwise, an error will be reported
In the same scope, unlike var, the same variable cannot be repeatedly declared using let
function qq(){ var a = 11; let a = 22; } // SyntaxError:Identifier 'a' has already been declared(标识符a已经被声明) function qq(){ let a = 11; let a = 22; }//SyntaxError: Identifier 'a' has already been declared(标识符‘a‘已经被重复声明)
When using var to declare a variable, repeated declaration errors will not occur The problem can be declared repeatedly, but using let can prevent duplication of variable naming and prevent variable pollution.
The error result is as follows:
[Related recommendations: javascript video tutorial, web front-end]
The above is the detailed content of Can let statements in es6 have the same name?. For more information, please follow other related articles on the PHP Chinese website!