JavaScript (ES2026) reference · String Methods

JavaScript String.raw() Method

A template-literal tag that returns the raw string, with backslash sequences left as written. Handy for regexes and Windows paths.

JavaScript (ES2026) Since ES2015

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

String.raw`template`

Parameters

ParameterDescription
template A template literal; ${} substitutions still work.

Return value

A string.

Examples

Backslashes stay as writtenTry it yourself
console.log(String.raw`C:\new\table`);
console.log(`C:\\new`);

Output

C:\new\table
C:\new
Building a regex sourceTry it yourself
const word = "camel";
console.log(String.raw`\b${word}\b`);

Output

\bcamel\b

Version history

VersionChange
JavaScript ES2015Added

Was this page helpful?