'JavaScript function default parameters [duplicate]

const add = (a = 1, b = 1, c = 1) => a + b + c
add(4, , 2)

Throws Uncaught SyntaxError, unexpected token ','

How do I call the function so b defaults to the value 1



Solution 1:[1]

Just take undefined as value.

const add = (a = 1, b = 1, c = 1) => a + b + c
console.log(add(4, undefined, 2));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nina Scholz