Home > Article > Web Front-end > How to implement addition in javascript
How to implement addition in javascript: 1. Create a front-end sample file; 2. Transform the string through the Number() function; 3. Use the "alert(Number(a) b);" method to specify Just add the numbers.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to implement addition in javascript?
First let’s take a look at the following addition operation:
The result obtained in this case is:
But if we encounter the following situation:
Then the value we get is the concatenation of strings:
In this case we need to transform the string, use Number():
to get the correct value:
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to implement addition in javascript. For more information, please follow other related articles on the PHP Chinese website!