JavaScript hoisting function vs function variable

前端 未结 4 931
礼貌的吻别
礼貌的吻别 2021-01-22 17:34

Here is my javascript code :

    console.log(a);
    c();
    b();            
    var a = \'Hello World\';
    var b = function(){
        console.log(\"B is ca         


        
4条回答
  •  甜味超标
    2021-01-22 18:24

    Function Expression:

      var b = function(){
            console.log("B is called");
        }
    

    Function Declaration:

    function c(){
        console.log("C is called");
    }
    

    Function Expressions loads only when the interpreter reaches that line of code.On the other side the function Declaration, it'll always work. Because no code can be called until all declarations are loaded.

    Read more about Function Declaration and Function Expression

提交回复
热议问题