Wednesday, June 13, 2012

Understanding writeOutPut function in ColdFusion

I was doing some some funny testing with writeOutPut() method of ColdFusion with iif() method.
My Code was:
<cfset iif(false, WriteOutput("It will execute IF TRUE"), WriteOutput("It will execute IF FALSE"))>

I got the out put:

It will execute IF TRUEIt will execute IF FALSE
then Error

Variable YES is undefined.

Here the question is why I am getting this error?

Then I made the testing with the following code:

<cfset c = writeoutput("hi")><cfoutput>#c#</cfoutput>

The out put of the above code was:

"hi YES".

After this out put I got my answer to first question i.e the writeOutPut() function returning some Boolean value but in "YES" and "NO"  format and iif() function treats that YES and NO as variable not as a Boolean value.

But, another question arises here When we gets the value NO/false in calling writeOutPut()?

If anyone know the answer of my question or my understanding is wrong . Please write your comment.


  1. I think writeOutPut function will never ever return "false"/"NO". If we pass a empty string also it returns YES.