当前位置:网站首页>On let variable promotion
On let variable promotion
2022-07-25 00:54:00 【Classmate Pan Pan】
let Whether the declared variable has variable promotion ?
We all know var Declared variables , There will be variable Promotion , Just before the variable declaration , Can be accessed .
The code is as follows
(function(){
console.log(x) //undefind
var x = "1111"
}())
there x What's printed out is undefind, It's because the variable increases , Everyone knows this, no problem
We're looking at a piece of code
var x = y = "global"
(function(){
console.log(x) //global
console.log(y) //global
}())
We use it var Variable declared x y by global, In the self executing function , We print x and y, All show global, No problem
Look again
var x = y = "global"
(function(){
console.log(x)//undifind
console.log(y)// Report errors The picture below shows
var x = "1111"
let y = "1111"
}())
It is also stated here x y by global , Print in the self executing function x and y, Just two more lines of code , Here the print x The result is undifind, Print y Will report a mistake ,x Print out undifind Because we defined it later var x=“1111”, The variable goes up , Print y Does the error report prove let Declared variables also exist, and variables are promoted , Otherwise, print y, Should be displayed global That's right .
After reading the above , I think you should know ,let There are also variable improvements , Let's take a look at the contents of the error report , Cannot access before initialization y, That's what's called let Of " Temporary dead zone ",let Declared variables , Cannot be accessed before declaration .
Let's see ,var To declare a variable establish initialization The process of assignment , Suppose you have the following code
function fn(){
var x = 1;
var y = 1;
}
fn()
- First, create variables in memory x and y
- Then initialize these variables to undifind
- Then execute the code in the function , Perform assignment operation
Look again. let Of
{
let x = 1
x = 2
}
- find let Declared variables , Create these variables in memory
- Then start executing the code , Note that there is no initialization operation here
- let x = 1, This step is the initialization operation , take x Initialize to 1
- x = 2 , This step is assignment
To sum up
var Declared variables , The creation and initialization phases have been upgraded
let Declared variables , The creation phase has been upgraded , There is no prompt during initialization
边栏推荐
- A string "0" was actually the culprit of the collapse of station b
- R language plot visualization: plot to visualize the residual analysis diagram of the regression model, the scatter diagram of the predicted value and residual corresponding to the training set and th
- MySQL的最左前缀原则
- Volley7 – networkdispatcher obtains data from the network [easy to understand]
- Deep and direct visual slam
- C language force buckle the flipped number of question 7. Violence Act
- If real-time intersection with line segments in online CAD drawings is realized
- How to better use the touchpad of notebook
- #648 (Div. 2)(A. Matrix Game、B. Trouble Sort、C. Rotation Matching)
- Measurement and Multisim Simulation of volt ampere characteristics of circuit components (engineering documents attached)
猜你喜欢

如果实现与在线CAD图中的线段实时求交点

Vegetable greenhouses turned into smart factories! Baidu AI Cloud helps Shouguang, Shandong build a new benchmark for smart agriculture

7.19 - daily question - 408
![Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation](/img/e1/51f750d355b248ab84e10f0e134271.png)
Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation

What is the function of transdata operator and whether it can optimize performance
![[acwing weekly rematch] 61st weekly 20220723](/img/8b/df2c8d516db1e7e5f2d50bcf62b2b1.png)
[acwing weekly rematch] 61st weekly 20220723

Esp32 OLED lvgl displays common Chinese characters

Detailed explanation of alexnet of paddlepaddle paper series (with source code)

Multi merchant mall system function disassembly Lecture 14 - platform side member level
![[leetcode weekly replay] game 83 biweekly 20220723](/img/db/c264c94ca3307d4363d3cf7f5d770b.png)
[leetcode weekly replay] game 83 biweekly 20220723
随机推荐
Kusionstack open source | exploration and practice of kusion model library and tool chain
C language word translation (to help understand the basic meaning of words) is updated from time to time
Moonpdflib Preview PDF usage record
Introduction to thread pool
The troubleshooting process of a segment error (disassembly address troubleshooting)
Verification of Kirchhoff's law and Multisim Simulation (engineering documents attached)
The use of Multimeter in circuit analysis experiment of Shandong University
Digital signal processing synthesis matlab design of dual tone multi frequency dialing system
Measurement and Multisim Simulation of volt ampere characteristics of circuit components (engineering documents attached)
Daily question 1 · 1260. Two dimensional network migration · simulation
7.20 - daily question - 408
If real-time intersection with line segments in online CAD drawings is realized
Join MotoGP Monster Energy British Grand Prix!
What can testers do when there is an online bug?
Server intranet and Extranet
C # "learning code snippet" - recursively obtain all files under the folder
px rem em
[untitled]
Dynamic programming-01 knapsack rolling array optimization
Add the two numbers in the linked list of the second question of C language. Ergodic method