I'm self teaching myself JavaScript from videos I've dug up from around the Internet. Most tend to gloss over things quickly and leave tons of questions. So I test things within Firefox 21 using Firebug 2.0.2 to see how they behave. That's the only purpose of the following code.
Console.log output
>>> var n=parseInt("34","22","18",10);console.log(n);
70
My initial thoughts was that it parsed each of the supplied strings and then returned the sum. Then I did the actual math and realized the sum should have came out to be 74 if that were the case.
Even more interesting, and what actually prompted me to do the math on my own instead of just trusting that to be the sum without thinking. When I reduced the value of one of the numeric strings (22 to 21 in my experience anyways) returned 67 instead of the expected 69.
in:10>>> var n=parseInt("34","21","18",10);console.log(n);
67
What is actually happening here? Is parseInt just not designed to accommodate multiple numeric strings?
No parseInt does not take multiple strings, it take one string and a optional radix (i.e. what base the number is in)
Please refer to the MDN reference here
Whats happening in your last example
parseInt("34","21","18",10)
is that you are telling javascript to parse 34 in base 21 (the other parameters 18 and 10 are ignored)
34 in base 21 is 67 (i.e. 3 x 21 + 4)
EDIT: and 34 in base 22 is 70 (3 * 22 + 4). See this answer for an informative approach to convert bases: https://answers.yahoo.com/question/index?qid=20090508092544AAxAokR
If you want to add up numbers, parse them individually first, then add them
i.e.
var n1 = parseInt("34",10);
var n2 = parseInt("22",10);
var n3 = parseInt("18",10);
var result = n1 + n2 + n3;
Also if you are positive that the strings only ever contain numbers (i.e. "22", not something like "22 widgets", because parseInt will parse everything up to the first non numeric character so parseInt("22 widgets") will return 22), then you can cheat a bit, and just put a + at the start
i.e.
var n1 = +"34";
var n2 = +"22";
var n3 = +"18";
var result = n1 + n2 + n3;
same outcome