Multiline strings

by Evin

Javascript is a very strange and often misunderstood language. One of the byproducts of the many different implementations are the many undocumented features. Among these is the very convenient, especially for fixture data, multi-line string. Here’s how you do it:

  var s= "\
          some text \
          some more lines\
          want line breaks? \n\
          javascript is cool\
  ";

Basically the last character of every line must be a \.

This entry was posted on Monday, December 22nd, 2008 at 7:34 pm and is filed under Javascript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply