-1

我目前正在对 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");

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

4

1 回答 1

0

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

shouldn't this work too

No. You want backticks to use string template literals

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

takeOrder("mushrooms");
于 2018-05-28T10:05:59.970 回答