I could use some help understanding the “typeof” operand.
If I remove “typeof” from the second if statement this code passes the test but I don’t understand why. If the second variable is undefined shouldn’t “typeof” return undefined and still trigger the if statement.
Instead of working I get TypeError: addTogether(…) is not a function
**Your code so far**
function addTogether() {
const [first, second] = arguments;
console.log(typeof(second))
if (typeof(first) !== "number")
return undefined;
if (typeof(second) == undefined)
return (second) => addTogether(first,second);
if (typeof(second) != 'number')
return undefined;
return first + second;
}
addTogether(2,3);
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/103.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Arguments Optional
Link to the challenge: