JavaScript 预解析 例子

1. 预解析分为 变量预解析 (变量提升) 和函数预解析(函数提升)

2.变量提升:把所有的变量声明提升到当前的作用域最前面 不提升赋值操作

3. 函数提升:把所有的函数声明提升到当前作用域的最前面 不调用函数

 预解析例


f1();
        console.log(c);
        console.log(b);
        console.log(a);

        function f1() {
            var a = b = c = 9;
            console.log(a);
            console.log(b);
            console.log(c);
        }
 //相当于执行以下操作
        function f1() {
            var a;
            a = b = c = 9; //var a=9;b=9; c=9; b和c直接赋值 没有var声明 当全局变量看
            console.log(a); 
            console.log(b); 
            console.log(c); 
        }
        f1();
        console.log(c); 
        console.log(b); 
        console.log(a); 

运行结果

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值