-2

When I type this code:

const name = "Stephen";
document.write("Hey ${name} how are you?");

All browser shows:

Hey ${name} how are you?

instead of:

Hey Stephen how are you?

What did I do wrong? isn't that E6 feature supposed to work? I tried Safari, chrome and everywhere it shows the same problem

  • 2
    It is supposed to work, however, you need backticks (``) for that, not quotes (""). – Endothermic_Dragon Mar 08 '21 at 00:37
  • 3
    You need to use the backtick `\`` instead of quotes `"` to make [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) – Hao Wu Mar 08 '21 at 00:37
  • 2
    String interpolation requires the usage of backticks instead of double quotes. Double quotes are simply ordinary strings. –  Mar 08 '21 at 00:37
  • @charlietfl This code doesn't throw an error. –  Mar 08 '21 at 01:08

1 Answers1

2

To use this feature, you have to use backtics:

const name = "Stephen";
document.write(`Hey ${name} how are you?`);
skuroedov
  • 77
  • 3
  • Thank you! lol, those Backtics look extremely similar to single quotation marks. Spent hours trying to figure it out. Thanks! – Emad El Sammad Mar 08 '21 at 02:12