手记

Multiline strings in JavaScript

I used to write multiline strings in JavaScript like this:


var str = 'This is ' +
'a very long ' +
'sentence.'

Sometimes, i wrote it this way:

var str = ['This is ',
'a very long ',
'sentence.'].join('');

Using array to contact strings is an effective way. I also see an implement of StringBuilder in JavaScript using this technology.

Today, i was surprised to find the third way:

var str = 'This is \
a very long \
sentence.';

just cool!

0人推荐
随时随地看视频
慕课网APP