DEV Community

Cover image for Parameter usage for default args in JS
icncsx
icncsx

Posted on

Parameter usage for default args in JS

A default argument can reference a prior argument.

const defaultFunc = (num1,num2=num1) => {
    console.log(`num1: ${num1} num2: ${num2}`)
}

defaultFunc(3)   // num1: 3 num2: 3
defaultFunc(3,6) // num1: 3 num2: 6
Enter fullscreen mode Exit fullscreen mode

Top comments (0)