-2
let name = "Ali"
const a = 'hi ${name}';
console.log.(a);

it works on online compiler but does not work while I am writing in vs code. it show output as '->hi ${name}' though I want the dynamic output like hi Ali.

  • 3
    You need to use backticks for string interpolation instead of single quotes: `\`hi ${name}\``. – code Aug 30 '22 at 01:01
  • This is not an issue with VSCode, it is a typo/misunderstanding of javascript syntax – Samathingamajig Aug 30 '22 at 01:04
  • Thankyou soo much I misunderstood the syntax. – Wahab Afridayy Aug 30 '22 at 01:09
  • It didn't feel right to downvote because I fell into the exact same thing when I started learning JS. – code Aug 30 '22 at 01:42
  • @code you are right. but thats okay – Wahab Afridayy Nov 03 '22 at 02:58
  • @WahabAfridayy sorry? – code Nov 03 '22 at 03:01
  • @code some people downvoted my question as i was new to js thats why i didnt knew abot backwards qoutes. – Wahab Afridayy Nov 03 '22 at 03:03
  • It's still important to try to figure things out though. The reason this question got downvotes and was closed was because "it does not show research effort." You can post better questions by knowing [ask] very well so people can answer and give you upvotes. For your situation try to search what you already have, like Google `javascript ${}`, or if you know the name `javascript template` or `javascript template literal`. Open a link and read it carefully, and it will tell you why it's not working. – code Nov 03 '22 at 03:08

1 Answers1

0

You need to use a template string: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

You need to be using a backtick (`), not a quotation (')