What is the meaning of "…args" in a Javascript function argument?

Question:

Reading a bit of Javascript code I have come across this:

router.route('/:id')
.put((...args) => controller.update(...args))
.get((...args) => controller.findById(...args));

Does anyone know what …args means?

Answer:

As a colleague commented to your question, they areRest Parameters , where simply this ( ...args ) is an object of type array that goes from 0 to args.length , example:

function fun1(...args) {
  console.log(args.length);
}

fun1();        // 0
fun1(5);       // 1
fun1(5, 6, 7); // 3
Scroll to Top