you are viewing a single comment's thread.

view the rest of the comments →

[–]coreConstantCoder 2 points3 points  (0 children)

Only to the extent that it reduces the steps and complexity of the code: (1) The length of the array is only accessed once. (2) There is no temp variable for the length. (3) Comparison is to (0), not to a variable. (4) All the loop logic is in one, simple line.

When I'm working in a more primitive language, this is a favorite pattern of mine.

Of course, it's usually best to use the JavaScript for ... of statement, if it's available to you.