Horje
Remainder Assignment(%=) Operator in Javascript

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



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
Exponentiation Assignment(**=) Operator in JavaScript Exponentiation Assignment(**=) Operator in JavaScript
Division Assignment(/=) Operator in JavaScript Division Assignment(/=) Operator in JavaScript
Count occurrences of all items in an array in JavaScript Count occurrences of all items in an array in JavaScript
How does Backbone.js relate to "traditional" MVC ? How does Backbone.js relate to "traditional" MVC ?
NuxtJS NuxtJS

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