DEV Community

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

Collapse
 
brooknovak profile image
brooknovak

Although it's really great to point out and discuss low level performance concerns for things like loops...

The majority of the time it's better to have maintainable and readable code over optimized code. Compilers and garbage collectors usually do a good job most of the time!

IMO creating variables outside a loop for the sake of optimization adds code smells for little to no benefit!