javascript - 在 nodeJs v4.4.2 中使用 ES6 模板文字

标签 javascript node.js ecmascript-6

我需要在 Node v4.4.2 中使用 ES6 模板文字。

设置 jsconfig.json 后,我无法正确创建我的字符串。

知道我在这里错过了什么吗?

var name = "Juan",
    job = "flying penguin";
var sentence = 'Hello${name},the ${job}!';
console.log(sentence);

------------ jsconfig.json

{
    "compilerOptions": {
        "target": "ES6"
    }
}

最佳答案

2 件事:

  1. ` 而不是 '
  2. $后没有空格

像这样:

var name = "Juan",
    job = "flying penguin";
var sentence = `Hello ${name},the ${job}!`;
console.log(sentence);

关于javascript - 在 nodeJs v4.4.2 中使用 ES6 模板文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36599963/

相关文章:

javascript - 将对象保持在边界内

javascript - javascript普通变量和带美元符号的变量的区别

javascript - 如何在模态内单击按钮时使用 jQuery 或 javascript 获取 Bootstrap 模态的数据值?

javascript - spread syntax (...) 究竟如何与 mapGetters 一起工作?

javascript - 在 Array.map() 中访问之前的父值

javascript - 使用 HTML5、Ajax 和 jQuery 发送表单

node.js - 如何使用 .htaccess 在 Apache 后面运行我的 NodeJS 服务器?

node.js - 带循环的 Mongodb 聚合管道

javascript - 从 bash 脚本运行 Node : output console. 日志

javascript - 分配静态类属性会在 babel 上触发错误