Assignment operators shorthand
+= is one of the more common ones. Most other calculations also have an assignment operator.
// regular assignment assigns the right value to the variable on the left a = b // we can shorten the code if the variable is itself part of the calculation a = a + 5 // is the same as: a += 5 // these are some of the available shorthand assignment operators a += b // a = a + b addition assignment a -= b // a = a - b subtraction assignment a *= b // a = a * b multiplication assignment a /= b // a = a / b division assignment a %= b // a = a % b remainder assignment a &&= b // a = a && b logical AND assignment a ||= b // a = a || b logical OR assignment
There is more to learn
Get free previews of my upcoming course materials and other bonus content to help you work smarter. I share tips straight to your inbox once a week. You can read previous mails in the newsletter archive.
Cannot show form because cookie consent was not given.