Horje
What is the use of the += operator in JavaScript ?

The += operator is a compound assignment operator used for addition. It adds the value of the right operand to the value of the left operand and assigns the result to the left operand.

Syntax:

a += b 

Example: Here, x += 3 is equivalent to x = x + 3. It adds 3 to the current value of x (which is 5), and assigns the result (8) back to x. Finally, console.log(x) prints the updated value of x, which is 8.

Javascript

let x = 5;
x += 3; // Equivalent to: x = x + 3;
console.log(x); // Output: 8

Output

8



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What are Comparison Operators in JavaScript ? What are Comparison Operators in JavaScript ?
Difference between Function Declarations & Function Expressions in JavaScript Difference between Function Declarations & Function Expressions in JavaScript
What is the use of the return Keyword in JavaScript Functions ? What is the use of the return Keyword in JavaScript Functions ?
What is the use of the Object.is() method in JavaScript ? What is the use of the Object.is() method in JavaScript ?
What is Event Capturing ? What is Event Capturing ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12