Search code examples
javascriptfunctionreturn

Does the return statement supersedes the other return statement in a function?


If i use a code like shown below,why the upper return statement takes precedence and the other return statemend after braces does not get executed.

function some4(array, f) {
  for (let i of array) {
    if (f(i)) return true;
  }
  return false;
}

Solution

  • Because once the return is executed it will terminate that function.