Saturday, November 15, 2025
HomeLanguagesJavascriptJavaScript String raw() Method

JavaScript String raw() Method

JavaScript String.raw() is a static method that is used to get the raw string form of template literals. These strings do not process escape characters. The method is similar to ‘r’ prefix in Python

Syntax:

String.raw(str, ...sub) 
String.raw`templateString`

Parameters: This method takes two parameters

  • str: It is the template literal array object
  • sub: This value contains the substituted values
  • templateString: It is the template literal string

Return Value: Raw string form of the template literal.

Example 1: This example prints a string on the console with and without the raw method.

Javascript




console.log(`DSA\nPython\nJava`);
console.log(String.raw`DSA\nPython\nJava`);


Output: When the raw method is used the escape characters are not processed

DSA
Python
Java
DSA\nPython\nJava

Example 2: This example will use the raw method on Unicode template literals.

Javascript




console.log(`\u2607`);
console.log(String.raw`\u2607`);


Output: The raw method ignores the Unicode declaration and processes the string in its own form

☇
\u2607

Supported Browsers: 

  • Chrome
  • Edge 
  • Firefox 
  • Opera 
  • Safari 

We have a complete list of Javascript string methods, to check those please go through this Javascript String reference article.

RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS