Friday, September 5, 2025
HomeLanguagesJavascriptFind quotient and remainder by dividing an integer in JavaScript

Find quotient and remainder by dividing an integer in JavaScript

In this article, we will find the quotient and remainder by dividing an integer in JavaScript. There are various methods to divide an integer number by another number and get its quotient and remainder. 

Example 1: This example uses the Math.floor() function to calculate the divisor. 

Javascript




let a = 39;
let b = 5;
function Geeks() {
    console.log("quotient = " + Math.floor(a / b))
    console.log("remainder = " + a % b);
}
Geeks()


Output

quotient = 7
remainder = 4

Example 2: This example uses the binary ~~ operator to calculate the divisor. 

Javascript




let a = 39;
let b = 5;
function Geeks() {
    let num = ~~(a / b);
    console.log("quotient = " + num)
    console.log("remainder = " + a % b);
}
Geeks()


Output

quotient = 7
remainder = 4

Example 3:This example uses the right shift >> operator to calculate the divisor. 

Javascript




let a = 39;
let b = 5;
function Geeks() {
    let num = (a / b) >> 0;
    console.log("quotient = " + num)
    console.log("remainder = " + a % b);
}
Geeks()


Output

quotient = 7
remainder = 4
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS