DEV Community

Heru Hartanto
Heru Hartanto

Posted on • Edited on

Clean your variable ๐Ÿงผ

Use meaningful names

Yes I know that you already know but honestly put meaningful name to a variable is not easy, just to remember that naming variable should be descriptive and usually javascript variable name write in camelCase and for Boolean variable name usually answer question such as isActive or hasParams

// โŒ Don't 

const x= "Jean Doe";
const bar= 23;
const active= true;

// โœ… Do

const fullName= "Jean Doe";
const Age= 23;
const isActive=true;
Enter fullscreen mode Exit fullscreen mode

No hardcode values

Hardcode is hard to maintain, instead of put constant values directly, you can put it inside a meaningful and searchable constants, by the way usually constant
write with SCREEEEEEEAM_SNAKE_CASE


function setConfig(hasKey=''){
    ...
};

// โŒ Don't 

setConfig('KLKJFI123123KJHF');


// โœ… Do

const HASH_KEY ='KLKJFI123123KJHF';
setConfig(HASH_KEY);


Enter fullscreen mode Exit fullscreen mode

Avoid unnecessary

Don't add redundant context to variable that already describe itself, your code is already long enough

// โŒ Don't 

const user:{
    userId:'12345',
    userPassword:'12345qwe',
    userFirstName:'John',
    userLastName:'Doe'
}

user.userPassword

// โœ… Do

const user:{
    Id:'12345',
    Password:'12345qwe',
    FirstName:'John',
    LastName:'Doe'
}

user.Password
Enter fullscreen mode Exit fullscreen mode

Top comments (0)