which and how javascript function will be called if we have 2 function declarations with the same name?

前端 未结 6 1496
旧巷少年郎
旧巷少年郎 2021-01-14 04:58

Take a test:


6条回答
  •  不要未来只要你来
    2021-01-14 05:32

    Basically, because of hoisting, which pulls all function declarations to the top of the current scope, the interpreter is basically doing this:

    function say() { alert( "ABOVE" ); }
    function say() { alert( "BELOW" ); }
    say();
    

    That is why it always ends up alerting below

提交回复
热议问题