当前位置:网站首页>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 .
边栏推荐
猜你喜欢
【R语言数据科学】:交叉验证再回首
源码编译安装MySQL
基于链表管理的单片机轮询程序框架
[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
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
ASP.NET Core入门一
Byte interview algorithm question
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
Dgraph: large scale dynamic graph dataset
随机推荐
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
OpenHarmony应用开发之如何创建DAYU200预览器
JVM series - stack and heap, method area day1-2
Lick the dog until the last one has nothing (state machine)
Automatic filling of database public fields
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
c#数组补充
XML入门二
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
Using scrcpy projection
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
动画与过渡效果
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
硬件基础知识-二极管基础
Node mongodb installation
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy