Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: grouped bar charts in chart js 
Javascript :: html video time 
Javascript :: slimscroll javascript 
Javascript :: set a variable in express.js 
Javascript :: java script or js circle collision 
Javascript :: js document on load 
Javascript :: bundle 
Javascript :: arrow function vs function in javascript 
Javascript :: what is the slice method in javascript 
Javascript :: initialize set with array javascript 
Javascript :: find second largest number in array javascript 
Javascript :: angularjs ng-options name value 
Javascript :: pass element from child to parent react 
Javascript :: label animation css 
Javascript :: how to decode jwt token in angular 
Javascript :: methods of object js 
Javascript :: merge two binary tree 
Javascript :: react validation form 
Javascript :: javascript force view to focus on a div 
Javascript :: change height of div with scroll in javascript 
Javascript :: inline styling js 
Javascript :: routerlink not working 
Javascript :: shape of array in js 
Javascript :: unexpected token react 
Javascript :: v-show example in vue js 
Javascript :: how to select default searchable dropdown value in jquery 
Javascript :: how to delete an exact element of array 
Javascript :: JavaScript substring Syntax 
Javascript :: javascript regex insert string 
Javascript :: javascript fade color 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =