0

Why in javascript a return with parentheses at the same line works but return undefined when parentheses is at a new line ?

this one works

addOne = (i) => {
  return (
    i + 1
  );
}

but this one return undefined

addOne = (i) => {
  return 
  (
    i + 1
  );
}
  • 1
    it is because javascript auto insert a semicolon after the return – Yousef Balout May 06 '18 at 08:32
  • It's plain Javascript problem. The return statement will be affected by automatic semicolon insertion (ASI). You could refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return. – Thomas Lee May 06 '18 at 08:30

0 Answers0