I use ternaries when it's a pretty simple conditional and need one of two possible values returned.
They are especially helpful in creating single line functions, for example....
/**
@func
find the largest word in an array
@param {string[]} a
@return {string}
*/constgetLongestStrInArr=a=>a.reduce((biggest,curr)=>curr.length>biggest.length?curr:biggest);//@testsconstaWords=["a","abcde","","abc","abcd"];console.log(getLongestStrInArr(aWords));// abcde
Nice comprehensive analysis Osumgba.
I use ternaries when it's a pretty simple conditional and need one of two possible values returned.
They are especially helpful in creating single line functions, for example....
Tenary operators are amazing especially in simple conditioning, but can get completed when you start nesting them.