Skip to main content

JavaScript: Assignment Operators

If you want to assign a value to a variable, then the assignment operator is used. It is used to assign values or do some operations to the values assigned to a variable.

1) = Operator

The = Operator assigns the values to the variables when declaring.

x = 99;

2) += Operator 

The += Operator adds the value inside the variable, or we can say which is assigned.

let x = 100;
x += 100;

console.log(x)

Output:

200

3) -= Operator

The -= Operator subtracts the values inside a variable and is relatively identical and opposite of what the += does.

let x = 100;
x -= 100;

console.log(x)

Output:

0

4) *= Operator

The *= Operator multiplies the values inside the variable.

let x = 100;
x *= 100;

console.log(x)

Output:

10000

5) /= Operator

The /= Divides the values inside the variable.

let x = 100;
x /= 100;

console.log(x)

Output:

1

6) %= Operator

The %= operator gives out the reminder of the values inside the variable, or we can say it gives out the leftover of the two values after division.

let x = 100;
x %= 100;

console.log(x)

Output:

0
Tags
Submitted by arilio666 on September 27, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.