+ 7

var myVariable = 26 % 6; document.write(myVariable); .... why it's output shows "2"??

1st Aug 2017, 4:01 PM
TONMOY SANTRA
TONMOY SANTRA - avatar
2 Answers
+ 16
26 / 6 = 24 with remainder 2. 26 % 6 returns the remainder of 26 / 6, which is 2.
1st Aug 2017, 4:05 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
It's output is 2 because, 26 divided by 6 = 4 with remainder 2. '%' sign stands for modulus, which means remainder. So, 26 divided by 6 will leave 2 as remainder, and 2 will be the output. Another example: 17 % 3 = 2
31st May 2018, 2:28 PM
Rahul Hemdev
Rahul Hemdev - avatar