How does Javascript execute code when duplicate named functions are declared?

后端 未结 2 408
野的像风
野的像风 2021-01-24 19:47

I\'m trying to understand why declaring a duplicate function after a statement has executed affects it.

It\'s as if JavaScript is reading ALL functions first,

2条回答
  •  别那么骄傲
    2021-01-24 20:05

    It's called Hoisting, all declarative functions and variable declarations are moved up, though undefined, at compilation.

    http://code.tutsplus.com/tutorials/javascript-hoisting-explained--net-15092

    http://bonsaiden.github.io/JavaScript-Garden/#function.scopes

    declarative function are functions like

    function name(){...}

提交回复
热议问题