MDN documentation says that:
“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.“
// Create a variable that uses a Windows// path without escaping the backslashes:const filePath = String.raw`C:\Development\profile\aboutme.html`;console.log(`The file was uploaded from: ${filePath}`);// Expected output: "The file was uploaded from: C:\Development\profile\aboutme.html"
This above example’s execution result looks like this:
> "The file was uploaded from: C:\Development\profile\aboutme.html"
If you run the same example without String.raw using the code below:
// Create a variable that uses a Windows// path without escaping the backslashes:const filePath = `C:\Development\profile\aboutme.html`;console.log(`The file was uploaded from: ${filePath}`);// Expected output: "The file was uploaded from: C:\Development\profile\aboutme.html"
Result looks like this:
> "The file was uploaded from: C:Developmentprofileaboutme.html"
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.