Search

Return the Remainder from Two Numbers in JavaScript

  • Share this:

To return the remainder from two numbers in JavaScript, you can use the modulo operator (`%`). The modulo operator returns the remainder of the division of one number by another.

Here is an example of how to use the modulo operator to return the remainder from two numbers:

var num1 = 10;
var num2 = 3;
var remainder = num1 % num2;
console.log(remainder); // Output: 1

You can also use the modulo operator in a function to return the remainder from two numbers:

function remainder(num1, num2) {
  return num1 % num2;
}

var result = remainder(10, 3);
console.log(result); // Output: 1

Note that if `num1` is divisible by `num2`, the remainder will be 0.

var num1 = 9;
var num2 = 3;
var remainder = num1 % num2;
console.log(remainder); // Output: 0
function remainder(num1, num2) {
  return num1 % num2;
}

var result = remainder(9, 3);
console.log(result); // Output: 0

 

Tags:

About author
I am a professional web developer. I love programming and coding, and reading books. I am the founder and CEO of StorialTech.