核心知识
参数与返回值
参数是函数输入,return 把结果交给调用者继续使用。
- 参数顺序与含义要清楚
- 没有显式 return 时返回 undefined
- console.log 只是输出,不代替 return
function total(price, quantity) {
return price * quantity;
}
const amount = total(20, 3);
参数是函数输入,return 把结果交给调用者继续使用。
function total(price, quantity) {
return price * quantity;
}
const amount = total(20, 3);