5 ms·
I don't mean to be mean but some of these answers depend on what language you use. For example var a = '3'; var b = '4'; a + b; Depending on the language may
by dubcanada 12y ago
I don't mean to be mean but some of these answers depend on what language you use.
For example
var a = '3';
var b = '4';
a + b;
Depending on the language may give you 7 or maybe give you 34.
- sp332 12y agoIn C it would be 103, or 'g'!
- matchu 12y agoWhat's an example of a language that, when adding two strings/chars, parses them as integers first?
- sp332 12y agoIn perl you use + for addition and . for concatenation. So '3' + '4' converts the strings to integers and returns an integer, and 3 . 4 converts them to strings first and returns a string.
- marcosdumay 12y agoPerl. Altough its adition only apply to numbers, so that would be a bad example, it does automaticaly interpret digit strings as numbers.
- manveru 12y agoHow about TCL? % expr "3" + "4" 7 % expr "3" + 4 7 % expr 3 + 4 7
- NhanH 12y agoIn addition to the answer of Perl and TCL, PHP would too, since the concatenate operator in PHP is "." - any dynamic and/or weak typing language that doesn't overload "+" for string concatenation will probably behave the same way.
- _pmf_ 12y ago> What's an example of a language that, when adding two strings/chars, parses them as integers first? The cancerous piece of shit we know as Javascript.
- croddin 12y agoNo, Javascript will concatenate two strings that contain integers if you add them. "1"+"1" //=> "11"
- notduncansmith 12y agoAs 'croddin pointed out, this is flat-out wrong - and that attitude is hardly conducive to a constructive discussion.
- jMyles 12y agoFor a = 3; b = '0'; I tried to give the answer "TypeError" which I thought deserved full credit, but alas, no. :-)
- notduncansmith 12y agoI hope that wrapping one of those values in quotes was a mistake, because I very much do not want to work in a language where concatenating two strings which happen to contain integers returns the sum of those integers.