Today I saw some JS code that was like:
const counterAxisAlignItems === 'MIN'
? 'flex-start'
: counterAxisAlignItems === 'MAX'
? 'flex-end'
: counterAxisAlignItems === 'CENTER'
? 'center'
: undefined;
took me a minute to realize that was essentially a select case statement using the ternary operator. Though it's kind of more like rewriting if/else statements. But I'm not sure why they didn't use a simple lookup object - this is just a mapping and an unknown key will return undefined as expected...
No comments:
Post a Comment