Favorites

JavaScript String.raw() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.raw()
JavaScript String Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The String.raw() static method is a template tag that returns a template literal's text without processing escape sequences such as \n.

Description

String.raw is a tag function for template literals. It returns the string with ${} substitutions filled in but backslash escape sequences left exactly as written, so \n stays as a backslash and an "n". It's handy for Windows file paths and for building regular expressions without doubling every backslash.

It can also be called as an ordinary function with an object that has a raw array, plus substitution values, though that form is rarely needed. Because it returns the text exactly as written in the source, a raw string can't end with an odd number of backslashes, since the final backslash would escape the closing backtick.

Tagged templates such as String.raw receive the string parts and the values separately, which is also the mechanism libraries use to escape HTML or build safe SQL queries. String.raw is the simplest example of the pattern built into the language.

Syntax

String.raw`template`

Parameters

  • templateA template literal. Escape sequences in it are left as written.

Return Value

The raw string of the template, with substitutions filled in.

Example

console.log(String.raw`C:\Users\new\temp`);
console.log(`line1\nline2`.length, String.raw`line1\nline2`.length);
const n = 3;
console.log(String.raw`\d{${n}}`);

Browser Support

The following information will show you the current browser support for the String.raw() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee