The support has been provided in ColdFusion for the Elvis operator (?:). The Elvis operator is primarily used to assign the ‘right default’ for a variable or an expression. In an expression, if the resultant value is not defined, then the object will be assigned to the left most part of the expression otherwise a default value (define at the right most part) will be assigned.
myDisplayName = userName ?: “Anonymous”;
In the above example, if userName is defined, it will be assigned to the myDisplayName variable. If the userName is not defined, the value “Anonymous” will be assigned to the myDisplayName variable.
See the following example:
employeeName = getEmployeeName(ID) ?: “Joe”;
In the above example, if getEmployeeName(ID) does not return any value, the value “Joe” will be assigned to the employeeName variable.
Similiarly, you can use this operator for Struct:
securityNumber = securityStruct[‘Joe’] ?: “”;