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

Did you find this page helpful?