ESC 6 variable and string part 3
Template Literals in ES6
Template literals are a way to output variables in the string.
Prior to ES6 we had to break the string, for example:
ES6 introduces a new way of outputting variable values in strings. The same code above can be rewritten as:
Notice, that template literals are enclosed by the backtick (` `) character instead of double or single quotes.
The ${expression} is a placeholder, and can include any expression, which will get evaluated and inserted into the template literal.
For example:
To escape a backtick in a template literal, put a backslash \ before the backtick.
Comments
Post a Comment