Home  >  Article  >  Web Front-end  >  What is temporary Zenless Zone Zero in es6

What is temporary Zenless Zone Zero in es6

WBOY
WBOYOriginal
2022-03-30 17:29:262908browse

In es6, the temporary dead zone is a syntax error, which means that the let and const commands make the block form a closed scope. Before using the let and const commands to declare a variable, the variable is unavailable. , es6 sets a proper term for this kind of error called temporary dead zone.

What is temporary Zenless Zone Zero in es6

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

What is the Temporary Dead Zone in es6

Temporary Dead Zone: Temporal Dead Zone, referred to as TDZ

In ES6, two new commands let and const are introduced , and there is no variable promotion for variables defined using these two commands, and the variable is unavailable until it is declared using let and const. This is called a temporary dead zone in syntax

console.log(a)
let a = 100  // ReferenceError

What does it mean? It means that es6 has set a proper noun for this kind of error called temporary dead zone. In fact, it simply refers to a grammatical error. When the control flow of the program is in When a new scope (module function or block scope) is instantiated, variables declared with let/const in this scope will be created in the scope first, but because they have not been lexically bound at this time, they It cannot be accessed, and an error will be thrown if accessed. Therefore, the period between when the running process enters the scope and creates the variable and when the variable can be accessed is called the temporary dead zone.

If you still can't remember, then just understand the following sentence:

ES6 stipulates that the let/const command will cause the block to form a closed scope. If you use a variable before declaring it, an error will be reported.

In short, within the code block, the variable is not available until it is declared using the let command.

This is grammatically called "temporal dead zone" (TDZ).

【Related recommendations:

javascript video tutorial

, web front-end

The above is the detailed content of What is temporary Zenless Zone Zero in es6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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