javascript pass all arguments to another function code example

Example 1: javascript pass all arguments to another function

function func1() {
  const reverse = func2(...arguments); // "rest operator" passes arguments
  return reverse.join("");
}

function func2() {
  return Array.from(arguments).reverse();
}

func1("a", "b", "c"); // "cba"

Example 2: js use param object or multiple

Like many of the others, I often prefer passing an options object to
a function instead of passing a long list of parameters, but it
really depends on the exact context.

I use code readability as the litmus test.

Tags:

Misc Example