From af6b10d2c6724f5bc8a3a1df0ef1050cddab79f1 Mon Sep 17 00:00:00 2001 From: "Dan G. Switzer, II" Date: Tue, 1 Mar 2022 11:40:54 -0500 Subject: [PATCH] Added important scope information --- .../01.functions/isnull/function.md | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/03.reference/01.functions/isnull/function.md b/docs/03.reference/01.functions/isnull/function.md index 5759099dd..0294f557c 100644 --- a/docs/03.reference/01.functions/isnull/function.md +++ b/docs/03.reference/01.functions/isnull/function.md @@ -8,4 +8,24 @@ categories: description: Determines whether given object is null or not --- -Determines whether given object is null or not +Determines whether given object is null or not. + +**IMPORTANT** — When testing the presence of `null` values unscoped variables will use scope precedence to determine if the variable exists in any scope. This behavior differs from Adobe ColdFusion. So when testing when local variables in a function are `null`, it’s important to prefix the variable with the `local` scope. + +For example, in the following code the variable `name` would return `false` for the `isNull()` if `name` ends up in a user supplied scope, such as the `URL` or `FORM` scopes: + +``` +function getName(){ + var name = nullValue(); + return isNull(name) ? "is null" : "is not null"; +} +``` + +In order to make sure that only the local `name` variable is checked, you would change the code to: + +``` +function getName(){ + var name = nullValue(); + return isNull(local.name) ? "is null" : "is not null"; +} +```