Javascript is a flexible language. It allows you to do things in multiple ways. One of these, is branching with switch or object literals. Many people have already debated as to what is the best way to write this. I personaly find the object literal cleaner.

See the Pen ZYbBZx by yves peeters (@drBenway) on CodePen.

Testing switch and object literal in jsPerf

Tests have proven that in javascript, the switch statement is faster then doing the same with an object literal. Take a look at the set in (jsperf)

Leave a Reply

Your email address will not be published. Required fields are marked *