Monday, June 15, 2015

Creating multiline strings in JavaScript


For a long strings, if you use return key in text editor for javascript, you may encounter an error for example:
var s1= 'test
 This is another line';

We can use \ in at the end of each line to create a multiline string  such as
var s1= 'test \
 This is another line';

We can also use string concatenation (better)
var s1= 'test'+
 'This is another line';

No comments:

Post a Comment