r/FreeCodeCamp • u/mikesprague mod • Apr 28 '16
Article 12 extremely useful hacks for JavaScript
https://blog.jscrambler.com/12-extremely-useful-hacks-for-javascript/
2
Upvotes
2
u/alayek mod Apr 29 '16
Don't agree with the 5th one.
causes a huge impact on the performance when processing large arrays during a loop
It could have been true in early 2011, but these days, compilers take care of such things. The code you write is not the code that gets executed.
Here's a nice video that discusses this.
1
u/[deleted] Apr 28 '16
In the "5) Caching the array.length in the loop" at the end, won't that last (3rd) piece of code...
for(var i = 0, length = array.length; i < length; i++) { console.log(array[i]); }...just recalculate the array.length each time too, since he left the
length = array.lengthcode as part of the for loop parameters?