IsNull()
Determines whether given object is null or not
IsNull( object=any );
Returns: Boolean
| Argument | Description |
|---|---|
|
object
any,
required
|
edit
Object for which you perform the null check. |
Usage Notes
editAlways use scoped variable references with isNull().
When a null argument shares a name with an outer-scoped variable, isNull() can return the wrong result / unexpected due to scope cascading:
name = "default";
function greet( name ) {
if ( isNull( name ) ) {
writeOutput( "Hello stranger" );
} else {
writeOutput( "Hello #name#" );
}
}
greet( javacast( "null", "" ) );
// Outputs: "Hello default" - found the outer variable, not the null argument!
Use scoped references to reliably check for null:
if ( isNull( arguments.name ) ) { ... }
if ( isNull( local.result ) ) { ... }
if ( isNull( variables.config ) ) { ... }
See recipe-null-support for more information on null handling in CFML.
Examples
editv1="test";
writeDump(isnull(v1));//false
v2;//Defining empty variable or v2=nullValue();
writeDump(isnull(v2));//true
See also
- Decision logic
- IsDefined()
- NullValue()
- StructKeyExists()
- Null Handling in CFML
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)