Skip to content

Latest commit

 

History

History
15 lines (15 loc) · 263 Bytes

3.default-augument.md

File metadata and controls

15 lines (15 loc) · 263 Bytes

函数参数的默认值

function multiply(a, b) {
    a = a || 5;
    b = b || 3;
    return a * b;
}

ES6可以写成

function multiply(a=5, b=6) {
    return a * b;
}
  • 如果只想传入第二个参数,第一个参数应该是 undefined