继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Multiline strings in JavaScript

代码写到手抽筋
关注TA
已关注
手记 294
粉丝 26
获赞 113

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!

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP