It's just a different way to write an if-else when you're working with a single variable (
a in this case).
That switch statement in your code translates to
PHP Code:
if (a == "0") {
player.y -= this.speed;
} else if (a == "1") {
player.x -= this.speed;
} else if (a == "2") {
player.y += this.speed;
} else if (a == "3") {
player.x += this.speed;
}
You can do slightly more complicated logic with switch statements, but I personally think those more complex uses of switch just makes things more confusing and bug-prone.