Do local variables inside of a loop get garbage collected?

后端 未结 3 1313
Happy的楠姐
Happy的楠姐 2021-01-27 03:17

I\'m wondering if it is more efficient to place any vars referenced within a loop, outside of the loop - or can they get garbage collected like vars inside of a function?

<
3条回答
  •  暖寄归人
    2021-01-27 03:54

    Neither will get garbage collected until the variables go out of scope. Scope in Javascript is introduced by functions. A loop construct has no influence on scope whatsoever.

提交回复
热议问题