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

0

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

2

Only works with backticks, not quotes.

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.