📜  10.4.2.函数默认值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:26.979000             🧑  作者: Mango

代码示例1
/*This example modifies the hello function to use a default value for 
name. If name is not defined when hello is called, it will use the 
default value.*/

function hello(name = "World") {
   return `Hello, ${name}!`;
}

console.log(hello());
console.log(hello("Lamar"));

//Hello, World!
//Hello, Lamar!