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

时间:2016-04-13 13:29:42

标签: javascript node.js ecmascript-6

我需要在Node v4.4.2中使用ES6 Template Literals。

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

知道我在这里缺少什么吗?

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

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

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

1 个答案:

答案 0 :(得分:12)

2件事:

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

    这样的事情:

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