Skip to content

Latest commit

ย 

History

History
25 lines (23 loc) ยท 482 Bytes

File metadata and controls

25 lines (23 loc) ยท 482 Bytes

Parameter defaults

function add(x, y) {
    return x + y;
}
console.log(add());         // NaN
console.log(add(1));        // NaN
console.log(add(1, 2));     // 3

function add2(x = 0, y = 0) {
    return x + y;
}
console.log(add2());        // 0
console.log(add2(1));       // 1
console.log(add2(1, 2));    // 3

์›๋ž˜๋Œ€๋กœ๋ผ๋ฉด ์ด๋ ‡๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ ํ–ˆ์„ ๊ฒƒ

function add(x, y) {
    x = x ?? 0;
    y = y ?? 0;
    return x + y;
}