What is the order of hoisting (function declarations vs var declarations) in JS as per modern Spec?

前端 未结 1 1396
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 11:43

There is this answer on Stack Overflow to support that JS function declarations hoist before variable declarations. It\'s based on very earlier version of Spec.

Link to t

相关标签:
1条回答
  • 2021-01-26 12:35

    I think the debate of hoisting order of function dec vs variable dec is not much relevant. Function decs are fully present in memory during creation phase. Only when a var declaration with same name as function is assigned a value , the function declaration is no more valid. But if there is just a var declaration with same name as function, it is ineffective. (This was actually a part of earlier spec) As per modern spec, it seems the order doesn’t matter since the declarations never actually move up. It’s actually those being in memory before execution phase. That’s why var coming before function or function coming before var declaration wouldn’t make a difference.

    0 讨论(0)
提交回复
热议问题