How to undefine a string

Tell us what’s happening:
I need to return the function “addTogether(2)([3])” undefined, for some reason I can’t return it undefined even though in my code strings should be undefined;

23 is not a number , it’s a string;

the results are okay, the only problem is that it is returning 23 instead of undefined:
5
5
23
undefined
undefined

Your code so far


function addTogether(a, b) {
  var sum = a + b;


if(typeof(sum) === "string") { return undefined; }

  else if (arguments.length === 1) {
  return function(b2) { // You could call this arg `b` as well if you like,
    return a + b2;      // it would shadow (hide, supercede) the one above
  };
} 

return sum;
}
console.log(addTogether(2, 3)); 
console.log(addTogether(2)(3)); 
console.log(addTogether(2)([3]));
console.log(addTogether(2, "3"));
console.log(addTogether("http://bit.ly/IqT6zt"));

Your browser information:

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

Challenge: Arguments Optional

Link to the challenge:

typeof has a weird syntax

1 Like

I don’t know what’s wrong with your code, but I tried it on jsfiddle and on your challenge link and it worked all fine

1 Like

Second function doesn’t check for type though, right? Think if you can re-use addTogether(a, b) here?

1 Like