• JavaScript中函数function fun(){}和 var fun=function(){}的区别


    function fun(){} 和 var fun=function(){}的区别

    标题有点长····

    废话少说,其实他们的主要区别就是“函数声明的提前行为”.

    var fun=function(){
        alert("hello world!");
    };
    fun();       //hello world!
    
    /**********************************/
    
    function fun() {
        alert("hello world!");
    }
    fun();       //hello world!

     正常情况下两种方式都会进行正常的编译,并输出“hello world!”,下面把函数调用放在上面再测一下。

    fun();       //报错
    var fun=function(){
      alert("hello world!");
    };
    /**********************************/
    fun();       //hello world!
    function fun() {
      alert(
    "hello world!");
    } 

     前者不会被提升,后者被提升到“顶部”

    最近在维护一个前端交流群,群内有各个领域的大佬,各路妹子,程序员鼓励师等你来撩,欢迎加入,群号:249620372
  • 相关阅读:
    类的设计问题
    php数组存在重复的相反元素,去重复
    常用JS验证函数总结
    python常用模块
    re 模块
    logging 模块
    configparser模块
    python 文件处理
    第15章-输入/输出 --- 理解Java的IO流
    第10章-验证框架 --- 验证器类型
  • 原文地址:https://www.cnblogs.com/wangyue99599/p/7347201.html
Copyright © 2020-2023  润新知