Just a quickie 🙂

I learned about ternary operators in JavaScript probably about 6 months ago, and absolutely fell in love with it.  After all, who doesn’t love to convert something bulky to something clean and able to fit on one line?

THEN:

var myidea = '';
if(thething=='yes) {
     myidea = 'great';
}
else {
    myidea = 'lame';
}

NOW:

var myidea = thething=='yes' ? 'great' : 'lame';

The other day, I was busting out some <cfscript>, and came across a bit of evaluation where a ternary operator would be PERFECT.  Having no idea whether or not it would work, I gave it a shot and voila!, it’s magic!

<cfscript>
     myidea = thething=='yes' ? 'great' : 'lame';
</cfscript>

Now after a bit more investigating, turns out this is in the “only works for CF9” domain.  Nonetheless, pretty nice–I love saving keystrokes!