当前位置:网站首页>JS pre parsing
JS pre parsing
2022-06-24 18:36:00 【Brother Mengfan】
Catalog
Four 、 Variable promotion reason
One 、 What is pre parsing
<script>
a = 2;
var a;
console.log(a);//2
</script>Two 、 Pre parse
2.1、 Variable pre parsing
<script>
console.log(age); // undefined
var age = 18;
</script>
Example 2:

After pre analysis :

2.2、 Function pre parsing

Example 1 Function pre parsing process :

Example 2:

Example 2 Function pre parsing process :

Be careful : If you use a function expression to declare a function , Will not be promoted .
3、 ... and 、 Statement notes
(1) Variable declaration and function declaration , Variable declaration promotion takes precedence over function declaration promotion . however , A function declaration overrides an undefined variable with the same name .
Example :

Pre parsing process :

(2) Variable declaration and function declaration , Variable declaration promotion takes precedence over function declaration promotion . If the variable has a value , Will not be covered .
Example :

Pre parsing process :

(3) The following function declaration will override the previous one
<script>
function fn() {
console.log('hello');
}
function fn() {
console.log('world');
}
fn(); //world
</script>summary : On declaration ( Whether it's a variable or a function ) Try not to take the same identifier ( name ).
Four 、 Variable promotion reason
<script>
console.log(fn()); // Output :1 \
console.log(n); // Output :undefined
function fn() {
return 1;
}
var n = 2;
</script> <script>
var a;
function fn() {
return 1;
}
console.log(fn());
console.log(n);
n = 2;
</script>边栏推荐
- Sword finger offer 10- ii Frog jumping on steps
- Several key points for enterprises to pay attention to digital transformation
- Tencent cloud TCS: an application-oriented one-stop PAAS platform
- Is there a security risk in opening an account online? What to do if the business department opening an account nearby is far away from home. Is there any capital requirement for opening an account?
- Leetcode weekly buckle 281
- What makes data analysts good- Cassie Kozyrkov
- Crmeb multi merchant PC packaging tutorial
- Differences between get and post request modes
- 国家出手了!对知网启动网络安全审查
- Restful design method
猜你喜欢

Wechat applet to realize stacked rotation

如何在 R 中使用 Fisher 的最小显着性差异 (LSD)

How MySQL works - Chapter 14

Business leaders compete for CIO roles
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers

13 skills necessary for a competent QA Manager
Online sequence flow chart making tool

Architecture decryption from distributed to microservice: several common microservice architecture schemes

Crmeb multi merchant PC packaging tutorial

Five skills of selecting embedded programming language
随机推荐
如何在 R 中执行幂回归
Regression testing strategy for comprehensive quality assurance system
Introduction to yottastore, a new generation of storage engine for VPC TCE cos
How to select the best test cases for automation?
Monotone stack template
Tencent cloud won the "trusted cloud technology best practice - virtualization"
中电投先融期货这家公司怎么样?期货开户办理安全吗?
Ten excellent business process automation tools for small businesses
Five skills of selecting embedded programming language
Selection (031) -cool_ How long can secret be accessed?
Overall planning and construction method of digital transformation
Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
Business based precipitation component = & gt; manage-table
股票网上开户安全吗?应该怎么办理?
EasyNVR使用Onvif探测设备失败,显示“无数据”是什么原因?
Selection (033) - what is the output of the following code?
Sudoku (easy to understand)
Three years of bug free, tips for improving code quality
Is it safe to open an account online? What should I do?
High quality defect analysis: let yourself write fewer bugs