0

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

Yousaf
  • 27,861
  • 6
  • 44
  • 69

2 Answers2

3

Just take undefined as value.

const add = (a = 1, b = 1, c = 1) => a + b + c
console.log(add(4, undefined, 2));
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
1

Pass undefined as value

Check this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#passing_undefined_vs._other_falsy_values

const add = (a = 1, b = 1, c = 1) => a + b + c
console.log(add(4, undefined, 2))
Sanket Shah
  • 2,888
  • 1
  • 11
  • 22