在js中当var遇到赋值时函数

在js中当var遇到赋值时函数

赋值时函数提升的是var,函数并没有提升

    fn();   //fn is not a function
        //   console.log(fn)  //undefined
      var fn=function(){
      console.log(3) 
  };
  fn()

执行过程如下

    var fn;
    fn();   //fn is not a function
    ;fn=function(){
      console.log(3) 
  };
  fn()

猜你喜欢

转载自www.cnblogs.com/cupid10/p/12793304.html