Does return stop a loop?

Yes, return stops execution and exits the function. return always** exits its function immediately, with no further execution if it’s inside a for loop.

It is easily verified for yourself:

function returnMe() {
  for (var i = 0; i < 2; i++) {
    if (i === 1) return i;
  }
}

console.log(returnMe());

** Notes: See this other answer about the special case of try/catch/finally and this answer about how forEach loops has its own function scope will not break out of the containing function.

Leave a Comment