String.raw()

A tag function for template literals that returns the raw string without processing escapes.

Since ES2015 Spec ↗

Syntax

String.raw`templateString`

Parameters

NameTypeRequiredDescription
strings object Yes A well-formed template strings array object with a `raw` property (supplied automatically when used as a tag).
substitutions any No The interpolated values in the template literal.

Returns

string — The raw string with escape sequences left uninterpreted.

Examples

console.log(String.raw`a\nb`);
Output
a\nb
const p = 5;
console.log(String.raw`C:\path\${p}`);
Output
C:\path\5

Notes

Primarily used as a template tag to keep backslash escapes literal (handy for regex sources or Windows paths). Interpolated `${...}` values are still substituted normally.

Browser & runtime support

EnvironmentSince version
chrome 41
firefox 34
safari 10
edge 12
node 4.0

See also