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