0
JavaScript modulus question
Can someone please explain how modulus works %
8 Respostas
+ 2
It's the reminder after the division. You can read more here:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators.
+ 1
Let's talk in integers, if you divide 12 by 24 then smallest number you can multiply 24 with to get a number smaller than 12 is only 0 (not talking about decimals here) so, 12-24*0=12
+ 1
thank you when i was figuring it out i was adding a decimal so my remainder didnt match the correct answer i got it now
0
it is an operator which gives you remainder
10%2 gives 0 as 2*5 = 10 and 10 - 10 =0
10%3 gives 1 as 3*3 = 9 and 10 -9 = 1
Why are you even asking this?
0
thats what i thought it was but i came across this question
what is the output of this code?
x= 12;
y= 24;
z= x % 24;
alert(z)
0
the answer is 12 but im not understanding why
0
The output is 12 because 24 is greater than 12