String.raw
Returns the raw string form of template literals, processing substitutions but not escape sequences
Syntax
String.raw(callSite, ...substitutions)Parameters
| Parameter | Type | Description |
|---|---|---|
| callSite | TemplateStringsArray | A well-formed template call site object |
| substitutions | any[] | Substitution values |
Return Value
The raw string form
Examples
const path = String.raw`C:\Users\Documents\file.txt`;
console.log(path); // 'C:\Users\Documents\file.txt'const regex = String.raw`\d+\.\d+`;
console.log(regex); // '\d+\.\d+'const newline = String.raw`Hello\nWorld`;
console.log(newline); // 'Hello\nWorld' (literal backslash-n)Understanding String.raw
The String.raw method in JavaScript returns the raw string form of template literals, processing substitutions but not escape sequences. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.
The method signature is String.raw(callSite, ...substitutions). It accepts 2 parameters: callSite, substitutions. When called, it returns the raw string form. Understanding when and how to use raw() helps you write more expressive, readable code.
Common use cases for String.raw include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-fromcharcode, string-fromcodepoint, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for String.raw is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More String Methods
Other methods in the String object
Related Tools
More String Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.