最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - print variables using ${ var } in javascript - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 6

you 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 ``

发布评论

评论列表(0)

  1. 暂无评论