DEV Community

Discussion on: Use lookup tables for cleaning up your JS/TS code

Collapse
 
mirzachilman profile image
Mirza Chilman

So what is the benefits of using a lookup table other than it looks much cleaner?

Collapse
 
alanpedro profile image
Alan Hutcheson

From the 1st link in the resources section:

  • Eliminate the branching by the if-else ladder and make the rule engine a simple O(1) lookup
  • Default evaluation does not need to wait for all conditions to get processed. If a key does not exist in the lookup table, it returns the default condition straightaway