Friday, September 19, 2025
HomeLanguagesJavascriptJavaScript Remainder Assignment(%=) Operator

JavaScript Remainder Assignment(%=) Operator

JavaScript remainder assignment operator (%=) assigns the remainder to the variable after dividing a variable by the value of the right operand.

Syntax:

Operator: x %= y
Meaning:  x  = x % y

Below example illustrate the Remainder assignment(%=) Operator in JavaScript:

Example 1: The following example demonstrates if the given number is divisible by 4 or if it’s an even or odd number.

Javascript




let num = 16;
 
// Test if its divisible by 4
if (num % 4 == 0) {
    console.log(true);
}
// Test for even number
if (num % 2 == 0) {
    console.log(true);
} else {
    console.log(false);
}
 
// Test for odd number
if (!(num % 2 == 0)) {
    console.log(true);
} else {
    console.log(false);
};


Output:

true
true
false

Example 2: The following example demonstrates if the given number is divisible by 2, 0, and world.

Javascript




let gfg = 3;
 
console.log((gfg %= 2));
 
console.log((gfg %= 0));
 
console.log((gfg %= "world"));


Output:

1
Nan
Nan

We have a complete list of Javascript Assignment Operators, to check those please go through the Javascript Assignment Operators List article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6666 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6745 POSTS0 COMMENTS