Multiple return in a function
It can be useful to have multiple returns in a function declaration as long as only 1 return is expected to run. For example:
function invert(x) {
  if (x === 0) {
     return 'input was zero';
  } else {
    return 1 / x;
  }
}
The function will still work using an if statement instead of an if...else statement
function invert(x) {
  if (x === 0) {
     return 'input was zero';
  }
  return 1 / x;
}
by Valeri Tandilashvili
2 years ago
JavaScript
return
0
Pro tip: use ```triple backticks around text``` to write in code fences