Difference between modulo operator and remainder

Hi! this is my first post here and I hope someone can help me.

Could anyone please explain to me, what’s the difference between remainder (%) and the modulo operator please?

HI @Zuko_1 I think they are the same , two names for the same thing in Js
Ex :

const a = 10;
const b = 3;

const remainder = a % b; // The value of 'remainder' will be 1 
//1 is the remainder and  % is the modulo operator 
so I think developer may say I am gonna use the remainder or I am gonna use the modulo and both refer to the same thing 
1 Like

Just to confirm, what @ka.eljaouhari says is correct – strictly speaking it’s not modulo (even though it gets called that). It is remainder. [someone may be able to correct me on the specifics here, but afaik:] It will produce the same result as modulo when the two numbers have the same sign, but [can?] produce a different result when they don’t.

If you actually want modulo, the equation is on MDN – instead of:

n % d

You would use:

((n % d) + d) % d

The distinction is IME not important for most day-to-day usecases (though YMMV)

1 Like

La diferencia principal radica en la aplicación y el contexto. El operador de módulo es una operación específica que calcula el residuo de la división, mientras que el término “resto” se utiliza de manera más general para describir cualquier cantidad que quede después de realizar una operación, ya sea relacionada o no con la división.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.