jskatas.org Continuously Learn JavaScript. Your Way.

Template strings: multiline

Template strings, can be multiline.

Template string, can contain multiline content

wrap it in backticks (') and add a newline, to span across two lines
var normalString = `line1 //// line3`; assert.equal(normalString, 'line1\n\nline3');
even over more than two lines
var multiline = ``; assert.equal(multiline.split('\n').length, 4);

and expressions inside work too

like simple variables
var x = 42; var multiline = `line 1 $ {x}`; assert.equal(multiline, 'line 1\n\n 42');
also here spaces matter
var x = 42; var multiline = ``; assert.equal(multiline, '\n\n42');


Description of multiline template strings.