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 |=.

AEle53valAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53valuA53 valuA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><1;d>AEle53couAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53counA53 counA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><2;d>AEconsB0objeAE = { property<: sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53objeA72proper5<3 sp ansty="le--0:#C792EA;--1:#8844">A53 objeA72proper5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><1;d>
44AE3F53v44A0<9820 spans="tyle--0:#D6DEEB;--1:#40">33F53va4430<9821 spans="tyle--0:#D6DEEB;--1:#40">3<= 1><;di vdivclass="Nameexpressive-">44AE3F53c44A0<9825 spans="tyle--0:#D6DEEB;--1:#40">33F53co4430<9822 spans="tyle--0:#D6DEEB;--1:#40">3<= 2><;di vdivclass="Nameexpressive-">44AEco61B0ob44AE = { proper0<9820 spans="tyle--0:#C792EA;--1:#88">4433F53ob4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72prop34430<9821 spans="tyle--0:#D6DEEB;--1:#40">3<= 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.