Jitendra Vyas - 4 months ago 46

Javascript Question

What is difference between 10/5 and 10%5 in JavaScript? Are both same ?

Answer

10/5 is division operation and depending on the data type storing the result in might not give you the result expected. if storing in a int you will loose the remainder.

10%2 is a modulus operation. it will return the remainder from the division and is commonly used to determine if a number is odd or even. take any given number mod 2 (N%2) and if the result is is 0 then you know the number is even.