davidpadua
12/4/2013 - 12:31 PM

Concatenating: Number to string and string to number

Concatenating: Number to string and string to number

//NUMBER TO STRING
var c = (16 * 24)/49 + 12;
d = c.toString();

//STRING TO NUMBER
//If you want to change a string to a number, \
//first make sure there are only the characters 0-9 in the string. \
//What I always do is simply multiplying the string by 1.

var c = '1234';
d = c * 1;

//Join two strings:

var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);

//The result of res will be:
//Hello world!

//Join three strings:

var str1 = "Hello ";
var str2 = "world!";
var str3 = " Have a nice day!";
var res = str1.concat(str2,str3);

//The result of res will be:

//Hello world! Have a nice day!