Home  >  Article  >  Web Front-end  >  How to add two variables in javascript

How to add two variables in javascript

青灯夜游
青灯夜游Original
2021-12-07 15:43:426722browse

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.

How to add two variables in javascript

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);

How to add two variables in javascript

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn