Skip to content

assignmentOperatorShorthands

Prefer logical assignment operator shorthand expressions.

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

ES2021 introduced logical assignment operators (||=, &&=, ??=) that combine logical operations with assignment. These shorthand operators make code more concise and express intent more clearly.

For example, a = a || b can be written as a ||= b. This pattern is common for providing default values or conditionally updating variables.

AEle53valAE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">53valuA53 valuAE<||sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><1;d>AEle53conf7<2:sp ansty="le--0:#C792EA;--1:#8844">A11ConfA7<2|sp ansty="le--0:#C792EA;--1:#8844">AB0undefin5<3;d ivclassNa="meec-li">53confiA53 confiAE5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0getDefaultConf53(<);d ivclassNa="meco"><);d>AEle53enablAE <= sp ansty="le--0:#FF6A83;--1:#A248">48fal5<3;d ivclassNa="meec-li">53enableA53 enableAE<&&sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0isFeatureAvailab53(<);d ivclassNa="meco"><);d>
44AE3F53v44A0<9820 spans="tyle--0:#D6DEEB;--1:#40">33F53va44A30<9821 spans="tyle--0:#D6DEEB;--1:#40">3<= 1><;di vdivclass="Nameexpressive-">44AE3F53co64<4AE spans="tyle--0:#FFCB8B;--1:#11">1111Co4<4AE spans="tyle--0:#7FDBCA;--1:#09">64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0undef33F53con44A361B0getDefaultCo3F5<3() ;divclass="Name"><;di vdivclass="Nameexpressive-">44AE3F53ena44A4848f33F53enab44A361B0isFeatureAvail3F5<3() ;divclass="Name">

This rule is not configurable.

If you need to support environments that do not have ES2021 support, you may need to avoid using logical assignment operators. You may also prefer the more explicit expanded form if you find it more readable.