Last Updated: February 25, 2016
·
921
· prettydeveloper

Javascript: if vs. case performances

I was writing some javascript code and I was in doubt if it would have been better to use a bunch of if...else conditions or a more clean switch...case statement, so I ran a simple test on jsperf, and it turns out that the switch statement is 79% slower than the corresponding if construct!

Obviously it may depend by other factors in case of a more complex code, but still from now on I will prefer simple if statements when possible.

Picture

1 Response
Add your response

Nice and useful test!

over 1 year ago ·