You actually can create a shorthand for calling functions conditionally, and I just found out this yesterday ðŸ˜
const type = 'greeting';
function greeting() {
console.log('hello')
}
function goodbye() {
console.log('goodbye')
}
if(type === 'greeting'){
greeting()
}else{
goodbye()
}
Instead of doing that, we can reduce our line number this way
(type==='greeting' ? greeting:goodbye)()
Top comments (0)