Wednesday, June 17, 2026
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

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS