Raw strings

A raw string is a normal string in which escaped characters aren't interpreted. We can create a raw string using a template string. We can get a raw version of a template string using the String.raw tag function. Here is an example to demonstrate this:

let s = String.raw `xy\n${ 1 + 1 }z`;console.log(s);

The output is as follows:

 xy\n2z

Here \n is not interpreted as a newline character. Instead, it is a raw string consisting of two characters, that is, \ and n. The length of variable s would be 6. If you create a tagged function and you want to return the raw string, then use the raw property of the first argument.

The raw property is an array that holds raw versions of the strings of the first argument. Here is an example to ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.