Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

What does String.raw do in JavaScript?

Do you know what will be the output of this code?

JavaScript
console.log(String.raw`HelloTwitter\nworld`);
Show answer and explanation

What String.raw actually does is taking a template literal, processing all substitutions (${variable}, e.g.), but ignoring well-known escape-sequences.

The following will be printed above: HelloTwitter\nworld

\n is a well-known escape-sequence, like \t is, e.g.

Those will simply be ignored and put into the resulting string, as they are.

Here an example of how String.raw works when you also include substitutions:

const varOne = "Hey";
const varTwo = "there";
const str = String.raw`${varOne}\t\n${varTwo}` // => "Hey\t\nthere"
Take the full quiz Next question →

More Strings questions

  1. Why does ('b' + 'a' + + 'a' + 'a') return "banana"?
  2. Why is "a string" instanceof String false?
  3. Why does 1 + "2" + "2" return "122"?
  4. Why is "10" < "9" true in JavaScript?
  5. Can you change a character in a JavaScript string?

Related topics