You are creating a function that accepts an arbitrary number of arguments and returns an array of those arguments. How would you use the rest operator in this scenario to collect all the passed arguments?

  • (function(...args) { return args; })
  • (function(args) { return args; })
  • (function([...args]) { return args; })
  • (function() { return ...args; })
To create a function that accepts an arbitrary number of arguments and returns an array of those arguments, you would use the rest parameter syntax (...args) in the function's parameter list. This syntax collects all the passed arguments into an array named args. The other options are either incorrect or do not use the rest operator correctly.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *