Skip to content

functionAssignments

Reports reassigning variables declared with function declarations.

✅ This rule is included in the ts javascript presets.

Reassigning a function declaration can make code harder to understand and maintain. Function declarations are hoisted to the top of their scope, and reassigning them can lead to unexpected behavior.

AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0calcula1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb1<1)sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEretu53 valuA5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">dB0calcula5<3 sp ansty="le--0:#C792EA;--1:#8844">A5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb1<1)sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C792EA;--1:#8844">AE<=>sp ansty="le--0:#D6DEEB;--1:#403F">53 valusp>A5<3 sp ansty="le--0:#F78C6C;--1:#AA09">8<23sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><3;d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processDa11<()sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0vo53< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53consoAB0l5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DProcessing.<..sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">d53processDatA5<3 sp ansty="le--0:#FF6A83;--1:#A248">48nu5<3;d ivclassNa="meco">AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0getVal11<()sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#F78C6C;--1:#AA09">82<42sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">d53getValAE<++sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><+;d>
44AEfunc361B0calcu1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v6361B0nu1<111) spans="tyle--0:#7FDBCA;--1:#09">6361B0nu3F<53 {divclass="Nameec-">de44AEre3F53 va4<4AE* spans="tyle--0:#D6DEEB;--1:#40">30<9822 spans="tyle--0:#D6DEEB;--1:#40">33c44AEco61B0re44A61B0calcu309<8210 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><10)><;di vdivclass="Nameexpressive-">44AEco61B0process44AE = funct11<11() spans="tyle--0:#7FDBCA;--1:#09">64<4AE spans="tyle--0:#C5E478;--1:#3B">61B044de3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DProcessin1<111" spans="tyle--0:#D6DEEB;--1:#40">34<4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3c61B0process34<4AE= spans="tyle--0:#D6DEEB;--1:#40">311<11() spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3F><53 {divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0log spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DDifferent proces1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">3F<53} ;divclass="Name"><;}><;di vdivclass="Nameexpressive-">44AE61B0getV44A11<11() spans="tyle--0:#7FDBCA;--1:#09">64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu44AE <=> {divclass="Nameec-">4444AEret09<8242 spans="tyle--0:#C792EA;--1:#88">4 ><4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3c61B0getV34<4AE= spans="tyle--0:#D6DEEB;--1:#40">311<11() spans="tyle--0:#D6DEEB;--1:#40">344 spans="tyle--0:#D6DEEB;--1:#40">3>098<2100 spans="tyle--0:#D6DEEB;--1:#40">3<100>

This rule is not configurable.

If you’re working in an existing codebase where reassigning function declarations is a common pattern and refactoring would be too costly, you might choose to disable this rule. However, using function expressions or const variables is generally a better practice when reassignment is needed.