what does this line mean z = (++b+—a)%5

``` var a = 3 var b = 2 z = (++b+—a)%5 document.write(z)
19 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MarkBoots
MarkBoots2y ago
++b = 3 --a = 2 b + a = 5 5 % 5 = 0
chrono1913
chrono19132y ago
so you can increment or decrement like that? usually its b++ or a— but you can ++b instead?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
chrono1913
chrono19132y ago
- - sry its suppose to be - -
MarkBoots
MarkBoots2y ago
++variable increments the variable, returning the new value. variable++ increments the variable, but returns the old value.
chrono1913
chrono19132y ago
so ++ variable means a = 3 is now a = 4
MarkBoots
MarkBoots2y ago
yep
chrono1913
chrono19132y ago
but variable ++ means a = 3 is still a = 3?
MarkBoots
MarkBoots2y ago
yes, but next time it is 4 so after the operation
chrono1913
chrono19132y ago
so would there be an operation like this? z = (b ++ + a- -)
MarkBoots
MarkBoots2y ago
it could be, but as said before, don't do it, it is just not readable
chrono1913
chrono19132y ago
o i saw it in a quiz thought i ask to know
MarkBoots
MarkBoots2y ago
there should not be spaces tho
chrono1913
chrono19132y ago
ya i just wanted to make that clearer lol
MarkBoots
MarkBoots2y ago
okay
chrono1913
chrono19132y ago
thanks for the help
MarkBoots
MarkBoots2y ago
np
chrono1913
chrono19132y ago
!close