DEV Community

Discussion on: Speed Up Your Javascript With These Simple Methods

Collapse
 
cavazzatommaso profile image
cavazzatommaso

I have a question about the reduce loop activity. Why it's not the same using array.length or a local variable? Array.length is not a method so why there will be less activity?

Collapse
 
dominik_gorczyca profile image
Dominik Gorczyca

Because code needs to look for property every time for loop iterates and then send the property value, when you store the result of Array.length, it's just a number, your code doesn't need to look for anything, it can just pass the value.
That's why it faster, I am not sure if the speed difference matters that much. Probably not.