Javascript

What is Variadic functions?

2020-11-25

In simple words variadic functions are functions that take an indefinite number of arguments

Defination: Variadic functions are functions that take an indefinite number of arguments.

For example, let’s say we have a function called sum() which calculates the sum of an indefinite amount of numbers. How might the sum() function be called during execution?

sum(1, 2)
sum(10, 36, 7, 84, 90, 110)
sum(-23, 3000, 575000)

There’s literally an endless number of ways the sum() function could be called. Regardless of the amount of numbers passed to the function, it should always return the total sum of the numbers.

Using the rest parameter(...)

We can define the function with n numbers of arguments using javscript rest param like following:

function sum(...nums) {
  let total = 0
  for (const num of nums) {
    total += num
  }
  return total
}

As a developer, I always see the problem for creating images/banners whenever I post some content online.

Even for simple designs I always needed to open figma or search online, so I thought of automating it.

I've build BannerPot to solve this problem, would you like to give it a try?

Ramesh from BannerPot

Ramesh Mhetre

Maker of BannerPot