DEV Community

Cover image for Object Lookups over Switch Statements and If/Else Conditionals

Object Lookups over Switch Statements and If/Else Conditionals

Lauren Clark on March 05, 2020

Why? Because they're neater, faster, easier to read and they are DYNAMIC. Switch statements need hardcoded values or at least a hardcoded reference...
Collapse
 
jankapunkt profile image
Jan Küster

Just in case you ever use a switch, the default case should be used to throw an error to reflect an unexpected state.

Collapse
 
laurenclark profile image
Lauren Clark

Yes in this case, not found. I agree it should have proper error handling but I'm not going to go into that for the purposes of this example.