Skip to content

Instantly share code, notes, and snippets.

@VictorOmondiCDS
Last active August 4, 2019 20:43
Show Gist options
  • Save VictorOmondiCDS/d0c6f45f684a4c6bf8052fea18fe0eff to your computer and use it in GitHub Desktop.
Save VictorOmondiCDS/d0c6f45f684a4c6bf8052fea18fe0eff to your computer and use it in GitHub Desktop.
Coding tip

Aviod using any magic numbers

Usecase:

if(memberCount > 256) {
  return 'member limit reached';
}

If you wrote the above code you might know what 256 mean here, but your teammates or any new comer will not know the reasoning behind using 256.

A better approach:

const MAX_MEMBER_COUNT = 256;
if(memberCount > MAX_MEMBER_COUNT) {
  return 'member limit reached';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment