Arguments OptionalPassed

Tell us what’s happening:
Describe your issue in detail here.
I can not understand how number 7 gets passed into the addSecond() function?

  **Your code so far**

function addTogether() {
const [first, second] = arguments;
// First argument is not a number
if (typeof(first) !== "number") {
  return undefined;
}
// First argument is a number
//  and second argument is not defined
else if (second === undefined) {
  function addSecond(second) {
    // New argument is not a number
    if (typeof(second) !== "number") {
      return undefined;
    }
    // New argument is a number
    else {
      return first + second;
    }
  }
  // Note: returning a *function*
  return addSecond;
}
// First argument is a number
//  and second argument is not a number
else if (typeof(second) !== "number") {
  return undefined;
}
// First argument is a number
//  and second argument is a number
else {
  return first + second;
}
}


console.log(addTogether(5)(7));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Arguments Optional

Link to the challenge:

So let’s simplify a bit. What if we did this:

const whatAmI = addTogether(5)

console.log(whatAmI); // ???

Now note our parameters. We have one, arguments[0] so what does addTogether pass back to us?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.