0

In many programming languages, you have function parameters:

function Something(param1, param2, param3) { }

However, it seems that function parameters can also appear as the following:

function Something({param1, param2, param3}) { }

What is the difference between these two notations in JavaScript? Which one is better in which circumstances?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Gibberish
  • 98
  • 12
  • Neither are better, they do different things. The first is three separate parameters, the second only uses one paramter and "destructures" the properties from the expected object. – evolutionxbox Apr 05 '21 at 15:55
  • [Destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) – Pointy Apr 05 '21 at 15:55
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Unpacking_fields_from_objects_passed_as_a_function_parameter – Dave Newton Apr 05 '21 at 15:56
  • To answer your question specifically, it's helpful to pass an options argument when passing them as individual parameters would be unwieldy. – lux Apr 05 '21 at 15:57

0 Answers0