JavaScript Clean Code ðŸ›
Only comment things that have business logic complexity. 💡
Comments are an apology, not a requirement. Good code mostly documents itself.
Bad :
Good :
âž–âž–âž–âž–âž–âž–
#JSTips #CleanCode
@ProgrammingTip
Only comment things that have business logic complexity. 💡
Comments are an apology, not a requirement. Good code mostly documents itself.
Bad :
function hashIt(data) {
// The hash
let hash = 0;
// Length of string
const length = data.length;
// Loop through every character in data
for (let i = 0; i < length; i++) {
// Get character code.
const char = data.charCodeAt(i);
// Make the hash
hash = ((hash << 5) - hash) + char;
// Convert to 32-bit integer
hash &= hash;
}
}Good :
function hashIt(data) {
let hash = 0;
const length = data.length;
for (let i = 0; i < length; i++) {
const char = data.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
// Convert to 32-bit integer
hash &= hash;
}
}âž–âž–âž–âž–âž–âž–
#JSTips #CleanCode
@ProgrammingTip
JavaScript Clean Code ðŸ›
Use consistent capitalization 💡
Bad :
Good :
âž–âž–âž–âž–âž–âž–
#JSTips #CleanCode
@ProgrammingTip
Use consistent capitalization 💡
Bad :
const DAYS_IN_WEEK = 7;
const daysInMonth = 30;
const songs = ['Back In Black', 'Stairway to Heaven', 'Hey Jude'];
const Artists = ['ACDC', 'Led Zeppelin', 'The Beatles'];
function eraseDatabase() {}
function restore_database() {}
class animal {}
class Alpaca {}
Good :
const DAYS_IN_WEEK = 7;
const DAYS_IN_MONTH = 30;
const SONGS = ['Back In Black', 'Stairway to Heaven', 'Hey Jude'];
const ARTISTS = ['ACDC', 'Led Zeppelin', 'The Beatles'];
function eraseDatabase() {}
function restoreDatabase() {}
class Animal {}
class Alpaca {}
âž–âž–âž–âž–âž–âž–
#JSTips #CleanCode
@ProgrammingTip