You are here: Home / Topics / Return the Remainder from Two Numbers in JavaScript

Return the Remainder from Two Numbers in JavaScript

Filed under: JavaScript on 2023-08-06 21:08:07

There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.
 

Examples

remainder(1, 3) ➞ 1

remainder(3, 4) ➞ 3

remainder(-9, 45) ➞ -9

remainder(5, 5) ➞ 0

<script>

function remainder(number1, number2){

return number1 % number2;

}

/*

To calculate the remainder of numbers we use % operator.

/*

var num1 = 5;

var num2 = 5;

console.log(remainder(num1, num2)); //this will print 0 in console.

</script>

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.