当前位置:网站首页>js之预解析
js之预解析
2022-04-23 06:25:00 【小白蛋挞】
目录
二、预解析分为变量预解析(变量提升)和函数预解析(函数提升)
一、js引擎执行代码分为两步:预解析和代码执行
1.预解析会将js里面所有的var,function的声明提升到当前作用域的最前面
2.代码执行,按照代码书写顺序从上往下执行
二、预解析分为变量预解析(变量提升)和函数预解析(函数提升)
1.变量提升
就是把所有变量声明提升到当前作用域的最前面,但不提升赋值操作。
2.函数提升
就是把所有的函数声明提升到当前作用域的最前面,但不调用函数。
三、案例
console.log(num1);
var num1 = 12;
//相当于
// var num1;
// console.log(num1);
// num1=12;
所以输出undefined
fn();
function fn() {
var a = 20;
console.log(a);
}
//相当于
// function fn() {
// var a = 20;
// console.log(a);
// }
// fn();
能正常输出20
fn1();
var fn1 = function() {
console.log(22);
}
函数表达式 调用必须写在函数表达式的下面

版权声明
本文为[小白蛋挞]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_61547956/article/details/124128647
边栏推荐
- 6. Aggregation function and grouping statistics
- SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
- Nacos / sentinel gateway current limiting and grouping (code)
- Hot change scheme and dynamic update strategy of mobile game
- H5 case development
- 组合数求解与(扩展)卢卡斯定理
- 如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
- 对STL容器的理解
- 13. User and authority management
- 菜菜的刷题日记 | 238.除自身以外数组的乘积
猜你喜欢

SAP PI/PO Soap2Proxy 消费外部ws示例

组合数求解与(扩展)卢卡斯定理

BTREE, B + tree and hash index

数论分块(整除分块)

Authorization+Token+JWT

Educational Codeforces Round 81 (Rated for Div. 2)

Visualization Road (IX) detailed explanation of arrow class

Reflection on the systematic design of Android audio and video caching mechanism

BTree、B+Tree和HASH索引

AuthorizationServer(授权服务器的简单搭建)
随机推荐
游戏辅助脚本开发之旅
如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
图论入门——建图
ABAP 从CDS VIEW 发布OData Service示例
【TED系列】一个习惯是如何改变我的一生
SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
ABAP 实现发布RESTful服务供外部调用示例
typescript字典的使用
Mvcc (multi version concurrency control)
[牛客挑战赛47]C.条件 (bitset加速floyd)
数论分块(整除分块)
5. Sql99 standard: internal connection and external connection
C语言的指针符号到底靠近变量类型还是变量名?
4. Multi table query
[Ted series] how does a habit change my life
redis连接出错 ERR AUTH <password> called without any password configured for the default user.
h5本地存储数据sessionStorage、localStorage
P1446 [HNOI2008]Cards(Burnside定理+dp计数)
页面动态显示时间(升级版)
【自我激励系列】到底是什么真正阻碍了你?