I just checked my manual. Apparently, the following should work:
var sum = parseFloat(s1) + parseFloat(s2);
Im just a disinterested observer though. I just tested it and
it seems to work too. Note the capitalisation is important.
The OP specifically stated that the result should be a string
representation of the result of the addition of the numeric values
represented by the original strings s1 and s2, and your result is
numeric, so not quite the whole answer and not substantially different
in effectiveness from the code Evertjan posted two days ago.
Solutions so far have stressed the importance of first converting the
strings s1 and s2 into numbers, for which any of the methods mentioned
in the FAQ are effective:-
<URL:
http://jibbering.com/faq/#FAQ4_21 >
Whether parseFloat could be preferred over the other methods would
depend on information not included by the OP. parseFloat is certainly
slower than any of the methods that force type conversion by applying
unambiguously mathematical operators to the strings. On the other hand
it scores over those other options in that when presented with an empty
string it will return NaN while the type-converting methods return the
number zero. When the desire is to perform addition, adding zero when
there is no input string may be acceptable/harmless, while accidentally
multiplying or dividing by zero may be sufficiently incorrect that a
testable NaN result would be preferable. It all depends on the context
(and could also be addressed by examining the input strings).
Also, if it was known that s1 and s2 were always integers (representable
in about 52 bits) it may be possible to use parseInt, and if the integer
range was more limited (32 bit signed integers) then it would be
possible to consider some bitwise operations as possible additional
type-converting methods (though they should not be able to outperform
unary plus at forcing type-conversion (and the internal toInt32 function
has its own ideas about how to handle unexpected input)).
Richard.