the singularity of being and nothingness
Posts tagged Ternary Operator

ColdFusion 9 and Ternary Operation
Jun 23rd
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!
Share this: