1

I have an issue. JavaScript do not recognize code inside curly braces:

let a = 'John'; let s = 'Hello ${a}'; // output: 'Hello ${a}' instead of 'Hello John'

I have updated Typescript to latest version: npm install typescript@latest

Borko Djurovic
  • 313
  • 2
  • 17

3 Answers3

3

You write single quotes, which doesn't have interpolation capability.

Please try "backtick" char, which will solve your issue

`Hello ${a}`

You can read more about this here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Aren Hovsepyan
  • 1,947
  • 2
  • 17
  • 45
2

Only works with backticks, not quotes.

Do `Hello ${a}` instead of 'Hello ${a}'

skara9
  • 4,042
  • 1
  • 6
  • 21
1

whenever you want to use template string, you have to wrap up with the backtick (type alt + 96), the correct syntax is:

`string ${YOUR_VARIABLE} string` 

read this document: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Nasser1245
  • 37
  • 1
  • 5
vahid ghadiri
  • 345
  • 1
  • 7