Evaluates a string value to determine whether the variable named in it exists.
NOTE: Passing an Array entry like isDefined('thisArray[2]') will error. Use ArrayIsDefined() instead.
NOTE 2: If you are evaluating a variable inside a structure, you may get a slight performance boost using StructKeyExists().

isDefined(variable_name) → returns boolean

isDefined Argument Reference

variable_name string

The quoted string of the variable to test for existence. If variable_name is passed without quotes and the variable doesn't exist, an error will be thrown rather than returning false.

Links more information about isDefined

Examples sample code invoking the isDefined function

Checking for the existence of a form variable.

<cfif isDefined("form.submit")>...</cfif>

Beware of scope evaluation order when checking for an unscoped variable name. = "" ; = ""; writeoutput("Is 'foo' defined? " & isDefined("foo")); writeoutput(isDefined("foo") ? " (" & foo & ")" : "");

Expected Result: Is 'foo' defined? YES (

Potentially unexpected behavior when checking for a dot-notation variable containing a scope name.

local["form.submit"] = "local['form.submit']" ; form.submit = "form.submit"; writeoutput("Is 'form.submit' defined?" & isDefined("form.submit")); writeoutput(isDefined("form.submit") ? " (" & form.submit & ")" : ""); writeoutput("<br>"); writeoutput("Is 'submit' defined? " & isDefined("submit")); writeoutput(isDefined("submit") ? " (" & submit & ")" : "");

Expected Result: Is 'form.submit' defined? YES (local['form.submit']) Is 'submit' defined? YES(form.submit)

Fork me on GitHub