🔰raw string
JS ⟩ value ⟩ primitive ⟩ String ⟩ raw string
// ⭐️ tag function (template function)
function raw(strings) {
// ⭐️ first argument (`strings`) has a special `raw` property
return strings.raw;
}
// ⭐️ tagged templates
raw`line 1 \n line 2`, // [ 'line 1 \\n line 2' ] (`\n` not escaped)
raw`5 = \n ${2 + 3}!`, // [ '5 = \\n ', '' ] (`\n` not escaped)
// ⭐️ raw strings
String.raw`5 = \n ${2 + 3}!`, // '5 = \\n 5!'
String.raw`5 = \n \${2 + 3}!`, // '5 = \\n \\${2 + 3}!'
// ⭐️ default template function
`5 = \n \${2 + 3}!`, // 5 = (new line)
// ${2 + 3}!
ignores escape sequences.
Last updated