var name = "Ana";
var greeting = "Hello " + name;
console.log(greeting);
name = "Maria";
console.log(greeting);
答案 0 :(得分:2)
如果您希望greeting
包含name
变量的当前值,则必须将其更改为函数:
var name = "Ana";
var greeting = () => "Hello " + name;
console.log(greeting());
name = "Maria";
console.log(greeting());