JavaScript Scope and Execution Context

前端 未结 2 1910
感情败类
感情败类 2021-01-05 19:25

I am trying to understand JavaScript scope rules. What I have read in textbooks and the documentation is confusing.

It seems to me that JavaScript is a statically (o

2条回答
  •  情话喂你
    2021-01-05 19:56

    It always comes down to lexical scoping which is function are executed with its scope chain when it is defined, not when it is invoked.

    The anonymous function is defined in the local scope of function changeColor instead of the global scope. Hence when it is executed again, it prints out the color green which is listed in the local scope of function changeColor.

提交回复
热议问题