Skip to content Skip to sidebar Skip to footer

Why A Newline Between `return` And `(` Breaks The Code?

Based on the solution of my question: setState fires and render method gets hit, but nothing rerenders Code works if there is NO newline between return and the (, and fails otherw

Solution 1:

Seems like Automatic Semicolon Insertion might be biting you in the butt. I believe javascript will insert a ; at the end of a return statement automatically.

Why doesn't a Javascript return statement work when the return value is on a new line?

Solution 2:

As answered here: Javascript function fails to return object when there is a line-break between the return statement and the object?

it's just a matter of JS syntax. Semicolons are automatically added and thus the compiler treats

return
  ( sth )

as

return;
  ( sth )

Post a Comment for "Why A Newline Between `return` And `(` Breaks The Code?"