Home > Web Front-end > JS Tutorial > body text

How to add two variables in javascript

青灯夜游
Release: 2021-12-07 15:43:42
Original
6611 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!