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.
Loading...
Related Quiz
- Which of the following is true about the global object in a Node.js module?
- In JavaScript, closures are crucial for functional programming as they facilitate the creation of ________.
-
Developers can use npm deprecate
[@ ] to mark a package or a specific version as deprecated, displaying a warning message ______ to any developers installing it. - What is the purpose of the res.send() method in Express?
- What is the main purpose of using mocking in unit testing?