JS: String.raw
String.raw
(new in ECMAScript 2015)
String.rawtemplateString-
return the string but leave the String Escape Sequence as is.
console.log(String.raw`\n` === "\\n" ); // true console.log(String.raw`\n`); // \n // prints literally backslash n // embeded expressions are still evaluated console.log(String.raw`${3 + 1}\n${3 + 2}`); // 4\n5 // without string raw console.log(`${3 + 1}\n${3 + 2}`); // 4 // 5
Common Use Cases
Regular Expressions
// replace digits by x. console.assert("5826".replace(RegExp( String.raw`\d+`), "x") === "x");
Windows file paths
const path = String.raw`C:\Users\John\Documents\file.txt`;
JavaScript. String
- JS: String Overview
- JS: Quote String
- JS: Apostrophe Delimiter String
- JS: Template String
- JS: String Escape Sequence
- JS: Unicode Escape Sequence
- JS: String Operations
- JS: Iterate String
- JS: String Index Code Unit
- JS: Count Chars in String 📜
- JS: String.raw
- JS: Tagged Template String
- JS: Regular Expression Functions
- JS: Convert String and Number
- JS: String (class)
- JS: String Constructor
- JS: String.prototype