
10 Things I Did as a Junior That Make Me Cringe as a Senior
Looking back at my code from 5 years ago feels like reading a diary from middle school. Here are the most cringeworthy habits I had, why they were wrong, and what I do instead now. 1. Commenting Every Line // Junior me: const users = []; // create empty array for users for ( let i = 0 ; i < data . length ; i ++ ) { // loop through data const user = data [ i ]; // get current user if ( user . isActive ) { // check if user is active users . push ( user ); // add active user to array } } return users ; // return the users // Senior me: return data . filter ( user => user . isActive ); Comments should explain WHY, never WHAT. If the code needs a comment to explain what it does, the code should be rewritten to be self-explanatory. The only valid comments: Why a non-obvious decision was made Warning about a subtle gotcha TODO with a ticket number 2. Reinventing Standard Library Functions // Junior me: "I'll write my own!" function removeDuplicates ( arr ) { const result = []; for ( const ite
Continue reading on Dev.to Beginners
Opens in a new tab




