Javascript Function Overloading Optional Arguments

Description

Javascript Function Overloading Optional Arguments


// Simulating optional arguments in functions
function addFiveNumbers(a,b,c,d,e) {
    let result = 0;
    if (a)//  ww w  .  ja v  a 2s.c  o m
        result += a;
    if (b)
        result += b;
    if (c)
        result += c;
    if (d)
        result += d;
    if (e)
        result += e;

    return result;
}
console.log(addFiveNumbers(1,2,3));    // 6



PreviousNext

Related