当前位置:网站首页>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>边栏推荐
- [NLP] 3 papers on how Stanford team builds a better chat AI
- [quick news] the jeecgboot low code platform was successfully selected into the 2021 scientific innovation China · open source innovation list
- SAP license: ERP for supply chain management and Implementation
- Gateway solves cross domain access
- R中的指数回归
- SAP license:sap s/4hana is the answer
- Do you know CMDB?
- Selection (031) -cool_ How long can secret be accessed?
- Seven strategies for successfully integrating digital transformation
- Restcloud ETL extracting dynamic library table data
猜你喜欢

C language - structure II

Complete Guide to web application penetration testing

How MySQL works - Chapter 14
[North Asia data recovery]_ mdb_ catalog. Mongodb database data recovery case in case of WT file corruption
![[NLP] 3 papers on how Stanford team builds a better chat AI](/img/f1/1c2ff31a728152395618800600df45.jpg)
[NLP] 3 papers on how Stanford team builds a better chat AI

110. balanced binary tree

Project Management Guide: tips, strategies and specific practices

How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?

Number of occurrences of numbers in the array (medium difficulty)

What is decision intelligence?
随机推荐
Why should state-owned enterprises accelerate the digital transformation
360 digital released information security trends in January: 120000 fraud risks were captured and users were reminded 2.68 million times
Crmeb multi merchant PC packaging tutorial
Five skills of selecting embedded programming language
国家出手了!对知网启动网络安全审查
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
Mental models: the best way to make informed decisions - farnam
Seven strategies for successfully integrating digital transformation
Get max value of a bit column - get max value of a bit column
Business leaders compete for CIO roles
[JS Framework] Failed to execute the callback function:
Selection (030) - what is the output of the following code?
About whether arm's large and small end mode is related to CPU or compiler
variable
RestCloud ETL抽取动态库表数据实践
Sword finger offer 10- ii Frog jumping on steps
Data modeling technology of Business Intelligence BI
Three layer switching experiment
SAP license: what is ERP supply chain
Introduction to yottastore, a new generation of storage engine for VPC TCE cos