function sayHi(name) {
return `Hi there, ${name}`
}
console.log(sayHi())Hi there,Hi there, undefinedHi there, nullReferenceError默认情况下,如果不给函数传参,参数的值将为undefined。上述情况,我们没有给参数name传值。 name等于undefined,并被打印。
在ES6中,我们可以使用默认参数覆盖此默认的undefined值。例如:
function sayHi(name =“Lydia”){...}
在这种情况下,如果我们没有传递值或者如果我们传递undefined,name总是等于字符串Lydia