Last Updated: February 25, 2016
·
4.261K
· 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: http://coderwall.com/p/6e7rea

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.

http://jsperf.com/if-switch-lookup-table/2

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 =)