Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to add number in string in javascript

const str1 = "4", str2="3";
// Use Number wrapper object
const sumUsingNumber = Number(str1) + Number(str2);
console.log(sumUsingNumber); // 7
// Use parseInt method
const sumUsingParseInt = parseInt(str1) + parseInt(str2);
console.log(sumUsingParseInt); // 7
// Use Unary plus
const sumUsingUnaryPlus = +str1 + +str2;
console.log(sumUsingUnaryPlus); // 7
 
PREVIOUS NEXT
Tagged: #add #number #string #javascript
ADD COMMENT
Topic
Name
9+9 =