Home > Web Front-end > Front-end Q&A > Can let statements in es6 have the same name?

Can let statements in es6 have the same name?

WBOY
Release: 2022-05-06 17:05:18
Original
1761 people have browsed it

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.

Can let statements in es6 have the same name?

The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.

Can the let declaration in es6 have the same name?

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‘已经被重复声明)
Copy after login

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:

Can let statements in es6 have the same name?

[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!

Related labels:
es6
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template