switch statement optimised?

C

Cameron McCormack

Hi.

I'm wonder whether any JS implementations optimise switch statements so
that they are any faster than a chain of if..else statements. I imagine
that something like

var s = ...;
switch (s) {
case "one":
...
case "two";
...
...
}

couldn't be optimised easily, but

var n = ...;
switch (n) {
case 0:
...
case 1:
...
...
}

could be (assuming that n was checked to be an integer).

Thanks,

Cameron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top