For loops in JS

What is the difference between for and forEach loop in JavaScript? Are there any advantages for using the one over the other? Can anyone provide with examples for each to show the difference in their outcomes?


  • In for loop you control the boundaries, in for each whole array will be iterated.
    Control vs simplicity, you choose which one you need at the given task.
    Outcome of both is the same when iterating through whole array.

    Note: for each is deprecated and not supported in browsers.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion