Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
How to Compose JavaScript Functions That Take Multiple Parameters (jrsinclair.com)
3 points by thunderbong on July 23, 2024 | hide | past | favorite | 1 comment


Are you talking about the var argument functions or the function which takes definite parameters?

Function with Var Args -

function sum(...numbers) {

  return numbers.reduce((total, number) => total + number, 0);
}

console.log(sum(1, 2, 3, 4, 5)); // Output: 15

Function with 2 Parameters -

function calculateArea(length, width) {

  return length * width;
}

console.log(calculateArea(5, 10)); // Output: 50




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: