DEV Community

Heru Hartanto
Heru Hartanto

Posted on • Edited on

1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay