Last Updated: February 25, 2016
· couto

Lookup Objects are not always faster.

While most Javascript books suggest about using lookup objects instead of switch statements, because lookup objects are faster, this is not always true.

Even some coderwall's users advise the same technique like:

It's not a bad advice really, but you need to realise that's it's actually faster to parse simple numbers than strings, meaning that an if/else or a switch statement can be actually faster than an object lookup.

So, just don't go blindly write object lookups every time you need a switch statement, think for yourself first and test performance when in doubt, specially because browsers keep optimising their internals, which might someday render this tip useless =)