0

I am working with javascript and right now trying to sum(add/plus) two variables but right now instead of "addition"(plus) variables are "concate",Here is my current code

var first = this.value; // getting value "5"
var second =$("#earning").val(); // getting value "2"
var final_value =first + second;
M

y expected result is "7"(5+2) but its giving me "52",how can i fix this ?

nice_dev
  • 17,053
  • 2
  • 21
  • 35
Jolly
  • 55
  • 3
  • Nothing surprising here! If strings are present as operands instead of integers, they are concatenated. Do `var final_value = parseInt(first) + parseInt(second)` – nice_dev Feb 08 '23 at 05:58
  • First result on Google. Does this answer your question? [How to force addition instead of concatenation in javascript](https://stackoverflow.com/questions/13953939/how-to-force-addition-instead-of-concatenation-in-javascript) – nice_dev Feb 08 '23 at 05:59

0 Answers0