DEV Community

Alex Yetto
Alex Yetto

Posted on

Immediately invoked object

We all know IIFE. In fact we can do the same with objects to omit cumbersome if/else, switch/case.

const color = {
    red: 'rgb(255, 0, 0)',
    green: 'rgb(0, 255, 0)',
    blue: 'rgb(0, 0, 255)'
}[props.color || 'red']
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
bias profile image
Tobias Nickel

this is fun πŸ˜‚