Assignment Operator in JavaScript

The javaScript assignment operator is used to assign a value to the left-hand side operand after performing the right-hand side operand operation. The assignment operator is used to overcome the arithmetic logic by analyzing the logic. The control for assignment operator is the prime operand must be any variable followed by equal (=) sign. After this equal sign, it is caught by any value or variable like integer, decimal, whole numbers, etc.

Syntax:)

variable+=variable

Assignment Operators Table in JavaScript:

Assignment-Operator-in-Java-Script

Examples of Assignment Operator in JavaScript:)

Following are the examples of assignment operators in javascript are given below:

Addition with Assignment operator in Javascript:)

<h2>The += Operator</h2>
<p id="num"></p>
<script>
var a = 780;
a += 6;
document.getElementById("num").innerHTML = a;
</script>

Subtraction with Assignment operator:)

<h2>The -= Operator</h2>
<p id="num"></p>
<script>
var a = 790;
a -= 4;
document.getElementById("num").innerHTML = a;
</script>

Multiplication with Assignment operator:)

<h2>The *= Operator</h2>
<p id="num"></p>
<script>
var a = 262;
a *= 3;
document.getElementById("num").innerHTML = a;
</script>

Division with assignment operator:)

<h2>The /= Operator</h2>
<p id="num"></p>
<script>
var a = 2358;
a /= 3;
document.getElementById("num").innerHTML = a;
</script>

Real-Time Outline: As usual, if we want to add the same variable to other Javascript variables then we use a=a+b. But we have other alternative ways to write the same logic with the same result by using assignment operator a+=b.

Leave a Reply

Your email address will not be published. Required fields are marked *