Answers for "how to add number in string in javascript"

2

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
Posted by: Guest on April-03-2022

Code answers related to "how to add number in string in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language