不确定如何在JavaScript中使用反勾号
这是我第一次使用backticks,我无法在FireFox或Chrome中使用我的函数。这是我的密码:不确定如何在JavaScript中使用反勾号,javascript,google-chrome,firefox,atom-editor,Javascript,Google Chrome,Firefox,Atom Editor,这是我第一次使用backticks,我无法在FireFox或Chrome中使用我的函数。这是我的密码: function makeLetter(fName, lName) { return `Dear ${fName} ${lName}, How are you today?`; } 当我输入makeLetter(hello,world)时,我得到以下错误: ReferenceError: hello is not defineddebugger eval code:1:1 <
function makeLetter(fName, lName) {
return `Dear ${fName} ${lName},
How are you today?`;
}
当我输入makeLetter(hello,world)
时,我得到以下错误:
ReferenceError: hello is not defineddebugger eval code:1:1
<anonymous> debugger eval code:1
ReferenceError:hello未定义debugger评估代码:1:1
调试器评估代码:1
我做错了什么?反勾号使用得很好。JavaScript解释器抱怨,因为它不知道
hello
或world
。您将它们作为变量传入,需要将它们作为字符串传入。像这样:
函数makeLetter(fName,lName){
返回'Dear${fName}${lName},
你今天好吗;
}
log(makeLetter('John','Doe'))代码>makeLetter(“你好”,“世界”)代码>它正在查找未定义的变量或fn。如果您没有设置变量,请将它们设置为字符串。非常感谢!现在我明白多了。我也会确保使用你的console.log提示!