xxxxxxxxxx
const cond = false;
const arr = [
cond ? ['a'] : []), (
'b',
];
>> ['b']
xxxxxxxxxx
const cond = false;
const arr = [
cond ? ['a'] : []), (
'b',
];
// result:
//if cond true: ['a','b']
//if cond false: ['b']
// from https://2ality.com/2017/04/conditional-literal-entries.html
xxxxxxxxxx
// Will result in ['foo', 'bar']
const items = [
'foo',
true ? ['bar'] : [],
false ? ['falsy'] : [],
]
console.log(items)
Run code snippet