jskatas.org Continuously Learn JavaScript. Your Way.

Template strings: raw property

The raw property accesses the string as it was entered.

Use the raw property of tagged template strings like so s.raw

the raw property accesses the string as it was entered
function firstChar(strings) { return strings; } assert.equal(firstChar`\n`, '\\n');
raw can access the backslash of a line-break
function firstCharEntered(strings) { var lineBreak = strings.raw; return lineBreak; } assert.equal(firstCharEntered`\n`, '\\');

String.raw as a static function

concats the raw strings
var expected = '\n'; assert.equal(String.raw`\n`, expected);
two raw-templates-string-backslashes equal two escaped backslashes
const TWO_BACKSLASHES = '\\'; assert.equal(String.raw`\\`, TWO_BACKSLASHES);
works on unicodes too
var smilie = '\u{1F600}'; var actual = String.raw`\u{1F600}`; assert.equal(actual, smilie);

Links

Description of `raw` property of tagged template strings.
Describing the raw behavior.