Use Case: Check to see selected value matches one of two acceptable options out of a larger list. If so, continue. Then, if that selection matches a certain value, apply a condition.
Here’s an example of the use case above:
- If value is “Raptor” or “Viper,” then go down the path.
- If value is “Raptor,” do this special thing, then continue down the path.
- If value is not “Raptor” or “Viper,” exit
Here’s a working sample:
When funFunction is called, it checks the value of #vehicle-selection. If the value selected by the user is either “Raptor” or “Viper,” the isSpaceCraft function returns “true” AND the value as ready and value, respectively.
If ready is true, funFunction then returns value to the console. In place of the ternary, you can build out the subsequent process flows.
Special thanks to Dr. Axel and his article Multiple return values in ECMAScript 6.
Also published on paulmiller3000.com.