tags:

views:

201

answers:

6

I'd like for something like 5 + 6 to return "56" instead of 11.

+12  A: 

Use "" + 5 + 6 to force it to strings. This works with numerical variables too:

var a = 5;
var b = 6;
alert ("" + a + b);
Kinopiko
Ok so, suposing the values 5 and 6 are in two variables:var1 = 5;var2 = 6;will it still work
Heidi
Yes, that will work. I've edited the answer to demonstrate.
Kinopiko
+5  A: 

just use:

5 + "" + 6
Brian Schroth
+4  A: 

simple answer:

5 + '' + 6;
Bryan McLemore
+8  A: 
var value = "" + 5 + 6;
alert(value);
jessegavin
+4  A: 
var output = 5 + '' + 6;
ACBurk
+1  A: 

Use

var value = "" + 5 + 6;

to force it to strings.

Nadir SOUALEM