Stump the CFChump – 2b
I am doing a "Stump the CFChump" series. I recently passed the ColdFusion 9 exam and this is material I learned while studying. I have several CodeSchool gift cards to giveaway so comments who answer correctly I'll email you the discount code. "Stump the Chumps" is from the "Car Talk" so I am spinning that title for ColdFusion. These are questions that stumped me when studying.
- Please try to not google or run the code before answering.
- Must have your correct email address when commenting to receive a CodeSchool giftcard
- Giftcards are available until I run out for correct answers
Stump the CFChump 2
Answer
Stump the CFChump 2b
Question
What will display when this code is ran?
<cfset myvar = "Hello ">
<cfif 1 eq true>
<cfset myvar = myvar & "Carrie">
<cfelseif 1 eq false>
<cfset myvar = myvar & "Brody">
<cfelse>
<cfset myvar = myvar & "Saul">
</cfif>
<cfoutput>#myvar#</cfoutput>
Answers
A. Hello Carrie
B. Hello Brody
C. Hello Saul
D. Error




Posted under:



This is where the fun oddities of an untyped variables comes into play. Since 1 and 0 are boolean true / false those numbers are handled differently. In this occurrence 1 is evaluated as boolean true thus 1 will eq true. The same would be true if the 1 was a 0 as it would evaluate to false.