Streaming on Twitch twice a week

Assignment operators shorthand


JavaScript has many different assignment operators that are shorthand for longer versions. += 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

More fire tips

Namespacing styled-components

To improve the readability of React components, we can import the styled-components they use from another file under a ui-namespace.

Read fire tip

Read all fire tips →