Javascript closures - variable scope question

前端 未结 5 1901
借酒劲吻你
借酒劲吻你 2020-11-28 13:15

I\'m reading the Mozilla developer\'s site on closures, and I noticed in their example for common mistakes, they had this code:

Helpful

5条回答
  •  孤城傲影
    2020-11-28 13:52

    New scopes are only created in function blocks (and with, but don't use that). Loops like for don't create new scopes.

    So even if you declared the variable outside the loop, you would run into the exact same problem.

提交回复
热议问题