Open In App

Remainder Assignment(%=) Operator in Javascript

Last Updated : 16 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Remainder Assignment Operator in javascript is represented by “%=”. This operator is used to divide the value of the variable by another operand and assign the remainder to the variable which is the first operand. This can be also explained as assigning the remainder to the first operand which is obtained by dividing the variable from the second operand.

Syntax:

x %= y 
or
x = x % y

Example 1: In this example, we will use the remainder operator.

Javascript




let a = 17;
console.log(a %= 2);
console.log(a %= 0);
console.log(a %= 'bar');


Output

1
NaN
NaN

Example 2: In this example, we will going to see the use of the remainder operator.

Javascript




let a = 28;
a %= 7;
console.log(a);
  
let b = NaN;
b %= 2;
console.log(b);


Output

0
NaN

We have a complete list of Javascript Assignment Operators, Please check this article Javascript Assignment Operator.

Supported Browser:

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 3
  • Safari 1

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads