Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of let in javascript

Shulou Source: shulou.com Published: 2022-05-31 13:07:40 09月24日 Update

This article mainly explains "what is the role of let in javascript". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the role of let in javascript"?

Let in javascript is a new keyword in ES6, and let allows us to declare a variable, statement, or expression that is scoped or restricted to the block level. Variables declared by let can only be global or entire function blocks.

This article operating environment: windows10 system, havascript 1.8.5, thinkpad T480 computer.

ES2015 (ES6) adds two important JavaScript keywords: let and const.

The let keyword allows you to declare a variable, statement, or expression that is scoped or restricted to the block level.

Unlike var, the variables it declares can only be global or entire function blocks. In other words, block level = {}

Variables declared by let are only available in the blocks or subblocks they declare, similar to var. The main difference between the two is that the scope of the variable declared by var is the entire closed function, while the scope of the declaration of let is block.

Function varTest () {var x = 1; if (true) {var x = 2; / / same variable! Console.log (x); / / 2} console.log (x); / / 2} function letTest () {let x = 1; if (true) {let x = 2; / / different variables console.log (x); / / 2} console.log (x) / / 1} at this point, I believe you have a deeper understanding of "what is the role of let in javascript". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Variables roles keys keywords functions different global content expressions statements learning restrictions practical deeper similar important two interest just practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info MariaDB Xiaomi Docker