Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to compare number to sum of numbers in JS (VUE)

New to JS and VUE.

I have a variable numberOfItems in my data which has 10 as its value.

I need to compare if this value is equal to the sum of 5 different variables data

var numberOfItems = 10
var destinations = (this.campaign.shipments_ue + this.campaign.shipments_uk + this.campaign.shipments_islas + this.campaign.shipments_peninsula + this.campaign.shipments_international)

I get 22222 in destinations value instead of 10, what method should I use to sum them up so I can compare them?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Observation : Looks like you are adding a string instead of number.

If data type is string then it is resulting of concatenating strings not a number.

For Ex :

var num1 = '10', num2 = '20';
console.log(num1 + num2); // 1020 (Here both the variables are string)

num1 = 10;
console.log(num1 + num2); // 1020 (Here variable 1 is number but variable 2 is a string)

num2 = 20;
console.log(num1 + num2); // 30 (Here both the variables are number)

Now, As per your requirement. You can use parseInt() function which helps in parsing a string argument and returns an integer.

Demo :

var num1 = '10', num2 = '20';

console.log(parseInt(num1) + parseInt(num2));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!