DEV Community

Heru Hartanto
Heru Hartanto

Posted on • Updated 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)