Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to add Strings as numbers 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 :: add toaster in angular 
Javascript :: create url with query parameters javascript 
Javascript :: addition of all elements of array in js 
Javascript :: node js event emitter 
Javascript :: how to find date in a string js 
Javascript :: Next js window is not defined solution 
Javascript :: assign array to another array javascript 
Javascript :: rgb javascript 
Javascript :: json stringify double quotes 
Javascript :: javascript count digits 
Javascript :: select field in react native 
Javascript :: repeat an array multiple times in js 
Javascript :: set localstorage 
Javascript :: js datetime format 
Javascript :: javascript slice vs splice 
Javascript :: generate apk debug react native 
Javascript :: react-active link 
Javascript :: get only numbers from string 
Javascript :: js base64 encoding 
Javascript :: react native vector icons not working 
Javascript :: javascript copy div element content 
Javascript :: js if else 
Javascript :: window.onscroll 
Javascript :: react date format 
Javascript :: javascript url pas array 
Javascript :: js new array from new set 
Javascript :: mongodb add key value to all documents 
Javascript :: completely remove duplicate element from the array 
Javascript :: javascript arrow function 
Javascript :: react conditional class 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =