JavaScript has been ruling the tech arena for more than two decades and helping developers simplifying complex tasks. It allows developers to implement complex task web pages in a most simplified manner. For most of the developers minified JavaScript...

Markdown supported · ⌘↵ to post
Nice article, I especially liked part about HTTP/2 multiplexing, indeed - every web server should make this requirement a MUST HAVE. However I can't agree on your note that :
I can't believe in this - at a lower level both code structures should be compiled into some sort of goto conditional jumps. Let's check. I've made a JS benchmark. This is switch block:
var rnd = Math.floor(Math.random() * 5); switch(rnd) { case 1: rnd += 1; break; case 2: rnd += 2; break; default: rnd += -1; }and this is if/else block :
var rnd = Math.floor(Math.random() * 5); if (rnd == 1) { rnd += 1; } else if (rnd == 2) { rnd += 2; } else { rnd += -1; }After pasting these blocks into jsbench.me performance comparison suite,- I've got results that switch block is SLOWER by [0% - 2%] on average. Given many unknown factors - how these tests are executed, JS implementation differences between browsers, execution speed measurement errors, biased outcome (maybe after 1000 or more runs performance difference would be 0%) and etc. - it would be rational to neglect these small execution time differences and for practical purposes keep that both should run at the same rate.