0

I was just wondering if it was possible to write a function in JavaScript without having any parameters in declaration parentheses but actually using them inside. For example in below, the function would give me 10 but if I want to change my parameter number to 5 and want to calculate sumThem(1,2,3,4,5); this function should give me 15 as result.

function sumThem() { //No parameters will be this line
  //let result = some magic will be in these lines... result become sum of all parameters.

  return result;

}

console.log(sumThem(1)); // should be 1
console.log(sumThem(1,2,3,4)); // should be 10
console.log(sumThem(1,2,3,4,5)); // should be 15


Barmar
  • 741,623
  • 53
  • 500
  • 612
Kaan G
  • 219
  • 4
  • 13

0 Answers0