Skip to content

Hoisting

variable hoisting

function hoisting

How hoisting work?

WRONG the variable or function are moving to the top

WRONG the variable or function are declared first and assign value later

CORRECT execution context was created in two phases:

  1. the create phase: create global object and outer environments, as the parser runs through, it set up the variables and the functions in memory(recognize where they placed, existed in memory), it’s available to access them, BUT variable is not like functions which are placed entirely in memory,  context knows the value only when it end up executing the code, when it access that variable, it got a placeholder undefined.
  2. the execution phase

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *