jskatas.org Continuously Learn JavaScript. Your Way.

Template strings: multiline

Template strings, can be multiline.

Template string, can contain multiline content

WHEN a new line is inside the backticks ` THEN the string can span across many lines
var normalString = ` line1 line2 line3 `; assert.equal(normalString, '\nline1\nline2\nline3\n');

GIVEN expressions inside of a template string

WHEN a simple variable is on the third line THEN it is also evaluated
var x = 42; var multiline = `line 1 $ {x}`; assert.equal(multiline, 'line 1\n\n 42');
AND spaces matter
var x = 42; var multiline = ``; assert.equal(multiline, '\n\n42');

Links

Description of multiline template strings.

Required Knowledge

Related Katas

Template strings

String API

Difficulty Level

BEGINNER

First Published

16 March 2015

Stats

3 tests to solve