How to use object as function parameter with default value in JavaScript

1 Answer

0 votes
function f({name = 'Dumbledore', graph = {x: 0, y: 0}, b = 3453} = {}) {
  console.log(name, graph, b);
}

f({graph:{x: 46, y: 31}, b: 20});



/*
run:

"Dumbledore", {
  x: 46,
  y: 31
}, 20

*/

 



answered Nov 14, 2020 by avibootz
...