Search 
DailyCoding > Scripting

Variadic Functions in JavaScript

Create and use function with indefinite number of parameters in javascript
Author admin on Jun 26, 2008 1 Comments
Rate it    (Rated 3 by 1 people)
171 Views

Like C# params, JavaScript also supports variadic functions. In variadic functions the total number of parameters are unknown and can be adjusted at the time of calling the function.

In computer programming, a variadic function is a function of variable arity; that is, one which can take different numbers of arguments. Support for variadic functions differs widely among programming languages.

In the javascript the parameters can be directly accessed into the function from the "arguments".

Take below example

function PrintList()
{
  for (var i = 0; i < arguments.length; i++)
  {
    document.write(arguments[i] + "<br />");
  }
}
// Call to Variadic Function
PrintList('Google', 'Microsoft', 'Yahoo', 'Adobe');
Javascript | Utility

Discussion

Mike Borozdin On Jun 27, 2008 12:00 PM
Thanks :)! I didn't know about that. By the way, it resembles me PHP at this point.

Leave a Comment

Name
Email Address
Web Site
© Copyright 2008 Daily Coding • All rights reserved