Skip to content
Advertisement

Simplify passing same arguments two two different functions

I’m calling two functions to which I pass the identical arguments.

JavaScript

Can I do something like the following, to declare the arguments once and then pass it to both functions?

JavaScript

Advertisement

Answer

Yes, you can: Put them in an array and use ... (in modern environments) or apply (in older environments):

In modern environments:

JavaScript

In older environments:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement