What is difference between 10/5 and 10%5 in JavaScript? Are both same ?
-
http://www.howtocreate.co.uk/tutorials/javascript/operators – Herberth Amaral Jul 26 '11 at 16:43
-
Possible duplicate of [How Does Modulus Divison Work](http://stackoverflow.com/questions/2664301/how-does-modulus-divison-work) – approxiblue Dec 02 '16 at 00:41
8 Answers
One is your basic division operation:
10/5 => 2
10/4 => 2.5
The other is the modulo operator, which will give you the integer remainder of the division operation.
10%5 => 0
10%4 => 2

- 41,216
- 30
- 109
- 147
10/5 divides 10/5 = 2
10%5 divides 5 and returns the remainder, 0, so
10%5 = 0

- 6,336
- 4
- 29
- 21
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.

- 592
- 4
- 9
- 25
% is the modulus operator: it gives you the remainder of the division.

- 11,316
- 5
- 48
- 62

- 29,685
- 30
- 94
- 128
10 / 5 is 10 divided by 5, or basic division.
10 % 5 is 10 modulo 5, or the remainder of a division operation.

- 6,982
- 16
- 51
- 59

- 1,259
- 8
- 17
In pretty much every language % is a modulus not a divide symbol. It does divide but it gives you just the remainder rather than the divided number.

- 650
- 3
- 8
- 20