1

I am not quite sure what this does.

<cfset User.ZeroBDK = FORM.ZeroBDK is "YES">

Is this short hand for

<cfset User.ZeroBDK = false>
<cfif FORM.ZeroBDK EQ "Yes">
     <cfset User.ZeroBDK = true>
</cfif>

Are there other truthy things that get set to true?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72

1 Answers1

1

The (FORM.ZeroBDK is "YES") expression will evaluate to true or false depending on what is in FORM.ZeroBDK,

so <cfset User.ZeroBDK = FORM.ZeroBDK is "YES">

will give to User.ZeroBDK a boolean value of true or false.


I'm just speculating..., but if you got this from some legacy code, it seems like not the best way to determine if FORM.ZeroBDK has something in it.

Alex Baban
  • 11,312
  • 4
  • 30
  • 44
  • Is it a string only comparison? – James A Mohler May 04 '18 at 17:27
  • are you trying to determine the exact string "YES" because `IS` is case insensitive and also `(1 is "YES")` will also evaluate to true? – Alex Baban May 04 '18 at 17:33
  • It is definitely a string only comparison. But be warned the value `"Yes"` will be considered as a `boolean` value by coldfusion. So the expression `foo IS "YES"` will return a boolean true (`Yes` in ColdFusion) if value of foo is `1+` or `true` . I have tested this. [Demo](https://www.trycf.com/gist/2a5854c7e1effa59377b13510302c948/acf?theme=monokai) – rrk May 05 '18 at 09:53
  • *Is it a string only comparison?* Not really. CF will do its automagic data type conversions. Meaning other values will evaluate to true as well, like "Yes", true, 1, -1, etc... If the goal is to accept *only* the literal string "YES", use `compareNoCase()` instead. – SOS May 05 '18 at 12:10
  • Correction, the strings `Yes`, `true`, `1` all evaluate to true. But `0`, `-1`, `100`, `""`, (space), `"Text"` all evaluate to false. But numbers <> 0 do evaluate to true if used solo, true` – SOS May 05 '18 at 12:51