Multi-line strings can be annoying in JavaScript. When in environments that support most ES6 features like Node.js, template literals can be used. But there are some situations where using transpilers is not practical and concatenated strings must be used. Fortunately, there join can be used instead of using string concatenation. Here is the comparison:
var firstName = 'Wealth', lastName = 'Jefferson'; var message = 'Hello ' + firstName + ' ' + lastName + ',\n\nAt Aramco, '; message += 'we realize how busy your time is. Which is why we are '; message += 'offering you a one time once-in-a-lifetime discount on '; message += 'new Jet Planes.'; console.log(message); // Hello Wealth Jefferson,...
var message = ['Hello ', firstName, ' ', lastName, ',\n\nAt Aramco, we ', 'realize how busy your time is. Which is why we are ', 'offering you a one time once-in-a-lifetime discount ', 'on new Jet Planes.'].join(''); console.log(message); // Hello Wealth Jefferson,...
And here is the template literal for comparison (assuming the line break is on column 70):
var message = ` Hello ${firstName} ${lastName}, At Aramco, we realize how busy your time is. Which is why we are offering you a one time once-in-a-lifetime discount on new Jet Planes`.trim(); console.log(message); // Hello Wealth Jefferson,...
Github Location: https://github.com/Jacob-Friesen/obscurejs/blob/master/2016/multiLineJoinString.js