Do local variables inside of a loop get garbage collected?

后端 未结 3 1310
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 04:02

    As far as garbage collection, what the other answers say should be true, the browser handles the garbage collection and it doesn't matter if the variable is declared internally, or externally, to a loop.

    As for efficiency, your code would be a little more optimized to declare the variable prior to the loop.

提交回复
热议问题