Skip to content Skip to sidebar Skip to footer

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 '
\

Solution 1:

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.


Solution 2:

I'm afraid not. Javascript sees the return-on-a-single-line and inserts a semicolon, ending the control flow.


Solution 3:

What comes closest to what you want is probably

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

Other then that I don't think it's possible


Post a Comment for "Return And Newlines?"