Are variables statically or dynamically “scoped” in javascript?

前端 未结 7 1929
無奈伤痛
無奈伤痛 2020-12-13 18:38

Or more specific to what I need:

If I call a function from within another function, is it going to pull the variable from within the calling function, or from the le

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 19:15

    if your next line is callMe();, then addMe will be 10, and myVar will be 0.

    if your next line is runMe();, then addMe will be 20, and myVar will be 10.

    Forgive me for asking - what does this have to do with static/dynamic binding? Isn't myVar simply a global variable, and won't the procedural code (unwrap everything onto the call stack) determine the values?

提交回复
热议问题