Using ES6 Template Literals in nodeJs v4.4.2

2019-07-25 14:50发布

问题:

I need to use ES6 Template Literals in Node v4.4.2.

After setting jsconfig.json I am not able to create my string properly.

Any idea what am I missing here?

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

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

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

回答1:

2 Things:

  1. ` instead of '
  2. No spaces after $

Something like this:

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