当前位置:网站首页>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 .
边栏推荐
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- 嵌入式编程中五个必探的“潜在错误”
- 面试拆解:系统上线后Cpu使用率飙升如何排查?
- #yyds干货盘点# 解决名企真题:连续最大和
- Go zero micro service practical series (IX. ultimate optimization of seckill performance)
- 安装trinity、解决报错
- Alibaba cloud award winning experience: build a highly available system with polardb-x
- Openharmony application development how to create dayu200 previewer
- In 2022, it will be es2022 soon. Do you only know the new features of ES6?
- AI painting minimalist tutorial
猜你喜欢

Interviewer: what is the internal implementation of hash data type in redis?
Three schemes to improve the efficiency of MySQL deep paging query

Oracle 被 Ventana Research 评为数字创新奖总冠军

中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东

JVM 内存布局详解,图文并茂,写得太好了!

Openharmony application development how to create dayu200 previewer

Introduction to reverse debugging PE structure resource table 07/07

Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)

2022年起重机械指挥考试模拟100题模拟考试平台操作

7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
随机推荐
XML入门二
Node の MongoDB安装
字节面试算法题
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
Database lock table? Don't panic, this article teaches you how to solve it
Introduction to reverse debugging PE structure resource table 07/07
Dgraph: large scale dynamic graph dataset
ViewBinding和DataBinding的理解和区别
2022G3锅炉水处理考试题模拟考试题库及模拟考试
c#数组补充
Introduction to XML I
Node mongodb installation
C语言个人通讯录管理系统
JVM系列——栈与堆、方法区day1-2
PostgreSQL 9.1 soaring Road
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
The old-fashioned synchronized lock optimization will make it clear to you at once!
光环效应——谁说头上有光的就算英雄
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc