简体   繁体   English

在 javascript 中使用 ${ var } 打印变量

[英]print variables using ${ var } in javascript

在此处输入图片说明

The above is a screenshot a tutorial in which the tutor used ${ var } to print a variable in js.上面是一个教程截图,其中导师在js中使用${ var }打印变量。

But when i ran the same code, i got like this:但是当我运行相同的代码时,我得到了这样的结果: 在此处输入图片说明

What is the actual problem?实际问题是什么?

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.它是大多数键盘上 1 键左侧的一个。

console.log( Server at port ${port} ) // Don't put "" or ''. console.log( Server at port ${port} ) // 不要输入 "" 或 ''。 Use ``使用``

在此处输入图片说明

you must use the backtick [ ` ] ;您必须使用反引号 [`] ; instead of the using [ ' ],So you can solve it.而不是使用['],所以你可以解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM