JavaScript String.raw() Method
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
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.
Desktop





Tablets & Mobile





