Skip to content

operatorAssignmentShorthand

Prefer assignment operator shorthand where possible.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

JavaScript provides shorthand operators that combine variable assignment and mathematical operations. These operators make code more concise and express intent more clearly.

For example, x = x + y can be written as x += y. This rule applies to the operators +=, -=, *=, /=, %=, **=, <<=, >>=, >>>=, &=, ^=, and |=.

let
let value: number
value
= 0;
let value: number
value
=
let value: number
value
+ 1;
let
let count: number
count
= 5;
let count: number
count
=
let count: number
count
* 2;
const
const object: {
property: number;
}
object
= {
property: number
property
: 0 };
const object: {
property: number;
}
object
.
property: number
property
=
const object: {
property: number;
}
object
.
property: number
property
- 1;

This rule is not configurable.

If you need to support environments that do not have all assignment operators, you may need to avoid using some shorthand operators. You may also prefer the more explicit expanded form if you find it more readable in specific cases.

Made with ❤️‍🔥 around the world by the Flint team and contributors.