0

Say I have function:

output = document.querySelector(".output")

function sum(a,b,c){
  return `${c},${a},${b}`
}

output.innerHTML = sum(b=2,c=3)
<div class="output"></div>

I need to define while calling, which of parametrs I exatly defining, but have no idea why its its sees "b=2" like "2".

Lama's
  • 21
  • 1
  • 4
  • 1
    you'll need to use an object if you want to pass named parameters, otherwise pass them in the order the function expects. `function sum({a,b,c}) {...} sum({b: 2, c:3}` – pilchard Nov 10 '21 at 22:16
  • See the Named Arguments section in [this answer](https://stackoverflow.com/questions/10855908/how-to-overload-functions-in-javascript/10855939#10855939). In Javascript, you would pass an object and then declare whatever properties you want on that object like this: `sum({b: 2, c: 3})`. The function implementation would grab properties off the passed object. – jfriend00 Nov 10 '21 at 22:31

0 Answers0