DEV Community

Discussion on: If-Else or Switch-Case: Which One to Pick?

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

In the if-else case, we do not create a jump table, and all cases are executed at runtime.

This is not necessarily true; compilers may still optimise if-statements into jump-tables if they're simple enough. Whether any compiler bothers doing this is another question, of course.


Also, another option is to build your own jump-tables. In JavaScript, these are called "objects" 😜