In which scenario we have to use ISNULL() function and ISEMPTY() function?
- ISNULL():
- Checks if the value is
null
. - A value is considered
null
if it has not been initialized or explicitly set tonull
. - Applies to arrays: An array is
null
if it does not exist in memory (i.e., it’s not initialized or points to anull
reference).
- ISEMPTY():
- Checks if the value exists (is not
null
) but contains no meaningful data. - For arrays, it means the array exists in memory, but its length is
0
(i.e., it has no elements). - Applies to arrays: An array is empty if it has been initialized but contains no elements (
length == 0
).
Data Type | Value | ISNULL() | ISEMPTY() |
---|---|---|---|
String | null |
true |
false |
"" (empty string) |
false |
true |
|
"hello" |
false |
false |
|
Array | null |
true |
false |
[] (empty array) |
false |
true |
|
[1, 2, 3] |
false |
false |
|
Object | null |
true |
false |
{} (empty object) |
false |
true |
|
{"key": "value"} |
false |
false |
Key Points to Remember:
- ISNULL checks for the absence of a value (null reference).
- ISEMPTY checks for the presence of a value but verifies if it contains meaningful data (e.g., length is
0
for arrays, no keys for objects, or empty for strings). ISNULL
is always checked beforeISEMPTY
because a null value cannot be empty.
2 Likes
@AnushkaGupta Thank you for explaining.
1 Like