Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add int to string javascirpt

var a = "1", b = "2", c = "3", result;

// Step (1) Concatenate "1", "2", "3" into "123"
// - concatenation operator is just "+", as long
//   as all the items are strings, this works
result = a + b + c; //123 string

// - If they were not strings you could do
result = a.toString() + b.toString() + c.toString(); // 123 string

// Step (2) Convert "123" into 123 (base 10)
result = parseInt(result, 10); // 123 number

// Step (3) Add 123 + 100 = 223
result = result + 100; // 223 number

// Step (4) Convert 223 into "223"
end_result = result.toString(); // 223 string

// If you concatenate a number with a 
// blank string, you get a string    
end_result = result + ""; //223 string
 
PREVIOUS NEXT
Tagged: #add #int #string #javascirpt
ADD COMMENT
Topic
Name
5+3 =