👋 Hello! I'm Alphonsio the robot. Ask me a question, I'll try to answer.
In JavaScript, how to create a string on several lines?
There are several ways to create multi-line strings in JavaScript:
With ES6, the simplest option is to use template literals:var str = `This is a string
on several lines`;
With ES5, new lines can be escaped with \
:
var str = 'This is a string \
on several lines';
Google JavaScript Style Guide recommends using string concatenation instead escaping new lines:
var str = 'This is a string ' +
'on several lines';