Ok, Let’s start with an example:
As you can see in the example, I have 2 variables where one is string and another one is integer. And in the 3rd variable, I am doing an addition of the first 2 variables. Now, If you run this code, it will output 99 instead of 18 !
But you need it to provide 18 as output. Let’s have a look at the ways to do that.
This code will output 18 which is perfect! Now let’s have a look at the other way.
You can use parseInt() function to convert string variable to integer. Let’s see how:
It will also return 18!
Pretty simple, wasn’t it ? 😉