当前位置:网站首页>Variable promotion and function promotion in JS
Variable promotion and function promotion in JS
2022-07-04 13:58:00 【51CTO】
js Variable promotion and function promotion in
The first value printed is undefined, The second printed value is yyyyy.
The actual method internal code execution order should be like this :
When you see the execution order of the split code, you are not confused about the results .
Why is there a variable increase
So why is there a phenomenon of variable Promotion ?
Actually js Like any other language , You have to go through the compilation and execution phases . and js During the compilation phase , All variable declarations will be collected and declared in advance , Other statements do not change their order , therefore , During the compilation phase , The first step has been carried out , The second step is to execute the statement at the execution stage .
summary
1.js Will promote the declaration of variables to js Top execution , So for this statement :var a = 2; Actually js It will be divided into var a; and a = 2; Two parts , And will var a This step is lifted to the top to perform .
2. The essence of variable promotion is actually due to js When the engine compiles , All variables are declared , So when executing , All variables have been declared .
3. When multiple variables with the same name are declared , Function declarations override other declarations . If there are multiple function declarations , The last function declaration overrides all previous declarations .
边栏推荐
- How to choose a technology stack for web applications in 2022
- Don't turn down, three sentences to clarify the origin of cross domain resource request errors
- Animation and transition effects
- 三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
- 嵌入式编程中五个必探的“潜在错误”
- Runc hang causes the kubernetes node notready
- 2022年起重机械指挥考试模拟100题模拟考试平台操作
- 数据库公共字段自动填充
- c#数组补充
- SQL语言
猜你喜欢
提高MySQL深分页查询效率的三种方案
Introduction to reverse debugging PE structure resource table 07/07
2022危险化学品经营单位主要负责人练习题及模拟考试
SCM polling program framework based on linked list management
面试拆解:系统上线后Cpu使用率飙升如何排查?
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
[AI system frontier dynamics, issue 40] Hinton: my deep learning career and research mind method; Google refutes rumors and gives up tensorflow; The apotheosis framework is officially open source
分布式BASE理论
Dgraph: large scale dynamic graph dataset
When MDK uses precompiler in header file, ifdef is invalid
随机推荐
CTF competition problem solution STM32 reverse introduction
XML入门一
Understanding and difference between viewbinding and databinding
C#基础补充
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
C language dormitory management query software
Fs4056 800mA charging IC domestic fast charging power IC
AI painting minimalist tutorial
一次 Keepalived 高可用的事故,让我重学了一遍它
ASP.NET Core入门一
OpenHarmony应用开发之如何创建DAYU200预览器
Five "potential errors" in embedded programming
逆向调试入门-PE结构-资源表07/07
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
2022年山东省安全员C证考试题库及在线模拟考试
Scrapy 框架学习
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Web knowledge supplement