function plus(a, b) {
return a + b;
}
function plusPlus(a, b, c) {
return a + b + c;
}
let res = plus(1, 2);
console.log('1+2 = ', res);
res = plusPlus(1, 2, 3);
console.log('1+2+3 = ', res);
function greet(name = "Friend", age = 18) {
console.log(`Hello, my name is ${name} and I am ${age} years old.`);
}
greet(); // Prints: "Hello, my name is Friend and I am 30 years old."
greet('maimai'); // Prints: "Hello, my name is maimai and I am 30 years old."
plus
函数接受两个参数 a 和 b,通过 return 语句, 返回这两个参数的和.
plusplus
函数接受三个参数 a, b 和c, 返回这三个参数的和.
执行
plus
函数执行
plusplus
函数函数可以有默认参数,‘name’ 参数具有默认值
’Friend’,age默认值为18