String raw()
The String.raw() static method is a tag function of template literals. This is similar to the r prefix in Python, or the @ prefix in C# for string literals. It's used to get the raw string form of template literals — that is, substitutions (e.g., ${foo}) are processed, but escape sequences (e.g., \n) are not.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 41 | 12 | 34 | 9 | 41 | 9 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
String.raw`Hello\
World`;
// 'Hello\\
World' (no line break)
// Windows path
String.raw`C:\Users\Admin\Desktop`;
// 'C:\\Users\\Admin\\Desktop' Live demo
escape-pcharacter. Disabledization
\n(change row) etc. specialcharacter that. character and output..
PreviewFullscreen
Use cases
-
Using String raw()
The String.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.