Thursday, December 22, 2011

ColdFusion Quickie: Setting A Boolean Value As A Result Of EvaluatingBooleans

There are many times when we come across a situation where we need to set a boolean value based on the value of other booleans.



Thats a lot of code for a simple statement. A better way is to use a ternary operator.



Better but still a bit more code than is actually necessary. In these cases where we are checking more than one variable for truthiness to set another variable to true we can just evaluate the result of concatenating the booleans together.



When concatenating booleans together the result is only true if all the values are true. One thing to be aware of is if you try to use the addition operator (+) instead and the value is true, you'll actually end up with an integer result instead of a true boolean. This may be good enough in some cases since any number other than 0 in ColdFusion is true anyway.
Fork me on GitHub