The above is a screenshot a tutorial in which the tutor used ${ var } to print a variable in js.
But when i ran the same code, i got like this:
What is the actual problem?
The above is a screenshot a tutorial in which the tutor used ${ var } to print a variable in js.
But when i ran the same code, i got like this:
What is the actual problem?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Dec 1, 2018 at 5:34 SuryaSurya 1,0914 gold badges18 silver badges33 bronze badges 3-
2
you used
'
to format the string, you have to use `(backtick) – chintuyadavsara Commented Dec 1, 2018 at 5:35 -
2
You need to use backtick(
`
) instead of'
. – vibhor1997a Commented Dec 1, 2018 at 5:35 - 3 What you are looking for is template literals. Take a look at this: stackoverflow./a/50922888/8349557 – Ajay Gupta Commented Dec 1, 2018 at 5:37
3 Answers
Reset to default 6you must use the backtick [ ` ] ; instead of the using [ ' ],So you can solve it.
You're using the wrong quote type. To do what you want you'll need to use backtick. It's the one to the left of the 1 key on most keyboards.
console.log(Server at port ${port}
) // Don't put "" or ''. Use ``