无法插值

时间:2018-05-28 10:03:43

标签: javascript apostrophe template-literals template-strings

我目前正在对javascript进行codecademy简介。

const takeOrder = (topping) => {
  console.log('Order: pizza topped with ${topping}');
};

takeOrder("mushrooms");

不应该这样做而不是

const takeOrder = (topping) => {
  console.log('Order: pizza topped with' +topping);
};

takeOrder("mushrooms");

我不知道为什么我不能这样插入?

1 个答案:

答案 0 :(得分:0)

console.log('Order: pizza topped with ${topping}');

  

不应该这样做

没有。您希望反引号使用字符串模板文字

const takeOrder = (topping) => {
  console.log(`Order: pizza topped with ${topping}`); //NB `
};

takeOrder("mushrooms");