DEV Community

Discussion on: Why you should stop declaring variables inside a for loop (especially in JavaScript)

Collapse
 
chriskarpyszyn profile image
Chris Karpyszyn

Declaring variables outside of your loop to use inside of a loop could cause unintended consequences if the code in the loop is complicated. Reusing variables might seem efficient until you need to fix a bug introduced by another developer.

Unless performance is really essential and in this case it's probably negligible, writing cleaner code is more important imo.