Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript redirect with extra url arguments 
Javascript :: build url query string javascript 
Javascript :: async await javascript stack overflow 
Javascript :: javascript progress of xml http request 
Javascript :: window.print filename 
Javascript :: js date in two weeks 
Javascript :: react compress image 
Javascript :: nodejs fs create file if not exists 
Javascript :: at in js 
Javascript :: export table data to excel in jquery 
Javascript :: getDataSnapshotFirebase 
Javascript :: duplicate elements of array multiple times 
Javascript :: convert arrow function to normal function javascript 
Javascript :: regex in mongo query 
Javascript :: check if an element is there in js 
Javascript :: create an element jquery 
Javascript :: next js page loader 
Javascript :: get image as blob 
Javascript :: count documents mongoose 
Javascript :: get match number array javascript 
Javascript :: js object clear 
Javascript :: javascript create object key from variable 
Javascript :: map list in javascript 
Javascript :: remove element from array lodash 
Javascript :: using html forms to define javascript variables 
Javascript :: falsy values javascript 
Javascript :: sum all values of an array 
Javascript :: hammer js 
Javascript :: join in mongodb 
Javascript :: callback hell javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =