Reputation: 1615
I have the following template literal
`<div class="date ${($.inArray(date, dates) == -1) && `outside`}">
<div>${date.format('D')}</div>
</div>`
When the expression ($.inArray(date, dates) == -1)
evaluates to true, the class outside shows up and nothing else, however, when it evaluates to false, false is outputted as a result of ${($.inArray(date, dates) == -1) &&
outside}
.
How could I avoid outputting false?
Upvotes: 2
Views: 1339
Reputation: 14541
You can use a ternary conditional operator: condition ? valueWhenTrue : valueWhenFalse
:
`<div class="date ${($.inArray(date, dates) == -1) ? `outside` : ``}">
<div>${date.format('D')}</div>
</div>`
Upvotes: 2
Reputation: 4106
Ternary operator:
($.inArray(date, dates) == -1) ? 'outside' : ''
Fallback to empty string:
($.inArray(date, dates) == -1) && 'outside' || ''
Upvotes: 2