Register to get access to free programming courses with interactive exercises

Functions with variadic parameters JavaScript fundamentals

Some functions have the interesting feature of accepting an indefinite number of parameters. And we're not talking about default values. Check out this example:

Math.max(1, 10, 3); // 10

The function Math.max() finds the maximum value among the passed parameters. How many parameters do you think it expects? This function's documentation shows something interesting:

  Math.max([value1[, value2[, ...]]])

The way it is written means this function accepts any number of parameters (even none). The optional parameters are specified by square brackets [ ], and so are the optional parameters with default values. The ability to pass any number of parameters is encoded with [, ...].

  Math.max(1, -3, 2, 3, 2); // 3

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

Bookmate
Health Samurai
Dualboot
ABBYY