Sometimes, we want to fix JavaScript (+) sign concatenating instead of giving sum of variables.
In this article, we’ll look at how to fix JavaScript (+) sign concatenating instead of giving sum of variables.
How to fix JavaScript (+) sign concatenating instead of giving sum of variables?
To fix JavaScript (+) sign concatenating instead of giving sum of variables, we should put parentheses around the expression that we want to add instead of concatenate.
For instance, we write
const divID = "question-" + (i + 1);
to wrap i + 1
with parentheses to return their sum instead of concatenating them.
Conclusion
To fix JavaScript (+) sign concatenating instead of giving sum of variables, we should put parentheses around the expression that we want to add instead of concatenate.