Clean Code: The " Lookup Table " Pattern

When you have too many case blocks in a switch, the code turns into an unreadable " bedsheet " . Professionals often replace such constructs with objects.

Object Example

const roles = {
  admin: 'Access to everything',
  editor: 'Access to articles',
  guest: 'Read only'
};

// Instead of a switch — one line!
let message = roles[role] || 'No access';

Scalability

The beauty of this method is that the roles object can come from an API or a separate configuration file. You don't need to dig into the program logic to add a new role.

Important

The object approach only works when you just need to map value A to value B.

Tip

In modern projects, this pattern is often used for interface translation (i18n): const t = { ru: "Привет", en: "Hello" };.