当前位置:网站首页>JS temporary dead zone_ Temporary
JS temporary dead zone_ Temporary
2022-07-29 09:59:00 【Java architects must see】
stay Js What is temporality in ?
The temporary dead zone is for 'const','let' The concept of these two keywords .
First, the variable raises this js The basic concept of ,'const' and 'let' As a block level scope, it cannot be avoided .
and 'var' Different , These two keywords limit the scope to ‘ block ’ in , In this block , The variables defined by these two keywords have been allocated memory .
That is, in fact ' There is ' 了 , But when the program is not executed to the declaration , Accessing this variable will report a reference error .
This is the time , For this variable, it is ' Temporary dead zone ', Generally speaking, this variable exists , But it doesn't exist completely Code up
This code is created by Java Architects must see the net - Structure Sorting
// The situation a 、
if (true) {
// TDZ Start
tmp = 'abc'; // ReferenceError
console.log(tmp); // ReferenceError
let tmp; // TDZ end
console.log(tmp); // undefined
tmp = 123;
console.log(tmp); // 123
}In the above code , stay let Command declaration variable tmp Before , All variables tmp Of “ dead zone ”.
// Scenario two
var tmp = 123;
if (true) {
tmp = 'abc'; // ReferenceError
let tmp;
}In the above code , There are global variables tmp, But in block level scope let A local variable is declared tmp, Causes the latter to bind the block level scope , So in let Before declaring variables , Yes tmp The assignment will report an error .
ES6 Make it clear , If a block exists let and const command , Variables declared by this block for these commands , Closed scopes have been formed from the beginning . Always use these variables before declaring them , You're going to report a mistake .
This code is created by Java Architects must see the net - Structure Sorting
// Scenario three
// Don't complain
var x = x;
// Report errors
let x = x;
// ReferenceError: x is not definedThe above code reports an error , It's also because of the temporary dead zone . Use let When variables are declared , As long as the variable is used before the declaration is complete , You're going to report a mistake . This is the case with the above line , In variables x Before the execution of the declaration statement is completed , Just go and get it x Value , Result in an error ”x Undefined “
That's the end of today's article , Thank you for reading ,Java Architects must see I wish you a promotion and a raise , Good luck every year .
边栏推荐
- Appendix 2 – some simple exercises
- A Zuo's realm
- Anfulai embedded weekly report no. 273: 2022.07.04--2022.07.10
- Dimensionality reduction and mathematical modeling after reading blog!
- C语言的传参方式(int x)(int *x)(int &x)
- Behind 100000 visits...
- Sample is new and supported from API 8! Come and take it
- 【微信小程序】接口生成自定义首页二维码
- Unity xchart3.0 basic usage quick start
- 手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
猜你喜欢

Some suggestions for programmers to leave single

What kind of framework is friendly to developers?

Pyqt5 rapid development and practice 6.5 qgridlayout (grid layout)

PyQt5快速开发与实战 6.5 QGridLayout(网格布局)
![[ts]typescript learning record pit collection](/img/4c/14991ea612de8d5c94b758174a1c26.png)
[ts]typescript learning record pit collection

Custom configuration

i.MX6ULL驱动开发 | 32 - 手动编写一个虚拟网卡设备

Summary of window system operation skills
![[wechat applet] interface generates customized homepage QR code](/img/9b/cccdb8ff6db61518402a27b94d0196.png)
[wechat applet] interface generates customized homepage QR code

Geeer's happiness | is for the white whoring image! Analysis and mining, NDVI, unsupervised classification, etc
随机推荐
div水平布局两边对齐
My problem solving record 1: the @component annotation is used on the class. If you want to use the methods in this class, you can't directly new, but should use @autowired for injection, otherwise an
[Apple Developer account]06 after transferring the developer account, the annual fee of the developer is automatically renewed
On memory computing integrated chip technology
Briefly describe the difference between heap and stack
Dimensionality reduction and mathematical modeling after reading blog!
7.9-7.17 new features and grammar of learning plan ES6
Div horizontal layout aligned on both sides
读博后降维打击数学建模!
TCP failure model
The function of that sentence
Sublime Text3 set different indents for different files
Read Plato farm's eplato and the reason for its high premium
Custom configuration
RTMP supports h265 streaming
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
SiC Power Semiconductor Industry Summit Forum successfully held
How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
Vector implementation
Unity3d hodgepodge