Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return and newlines?

I was messing around with something today, where I'm returning a DOM tree. I was wondering if there was a way to have the code be like:

return
  '<div id="something"> \
     <p>Stuff</p> \
   </div>'

instead of:

return '<div id="something"> \
     <p>Stuff</p> \
   </div>'

just for aesthetic reasons - the first one looks better. I Googled it for about 10 minutes, then figured I ought to just ask those who know more than me.

like image 423
Connor Avatar asked May 25 '26 04:05

Connor


1 Answers

No, it isn't.

A new line after a return triggers semi-colon insertion, so the code is equivalent to:

return;
  '<div id="something"> \
     <p>Stuff</p> \
   </div>';

…and you return undefined.

like image 188
Quentin Avatar answered May 27 '26 17:05

Quentin