Home >Web Front-end >JS Tutorial >How to add two variables in javascript
Javascript method to add two variables: 1. Use the " " operator, the syntax is "x y", which means that the variable x and the variable y are added together; 2. Use the "=" operator, The syntax is "x = y", which means that variable x and variable y are added together and the result is assigned to variable x.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In javascript, you can use the "
" or " =
" operator to implement addition.
Operator | Description | Example |
---|---|---|
Addition Operator | x y means calculating the sum of x plus y | |
= | Perform the addition operation first, and then assign the result to the left side of the operator Variable | x = y is equivalent to x = x y |
Example:
var x = 10, y = 5, a; a=x + y; x+=y; console.log(a); console.log(x); a=x + y; console.log(a);
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to add two variables in javascript. For more information, please follow other related articles on the PHP Chinese website!