Is there a better way to check NULL

Hi there,
is there a better way to check whether the value is NULL or empty?
I am getting errors when I receive a null value

Thank you in advance.

Hey @tuliovargas,

Welcome to the community :sparkling_heart:

Can you please share what exactly you’re trying to do? Also, if you can share the error you get, it will be helpful to debug :slight_smile:

hi @harshil1712 , thank you for your prompt answer.
Sometimes I get the filed
items[0].json.result.ADDRESS_POSTAL_CODE

with value inside like “1234”, however sometimes the API sends this field NULL, then I’d like to check before if this field is populated or not.

Can you share what value does the API return? Does it return NULL or it doesn’t return that particular field?

To avoid the error you can try using optional chaining.

In your example it would be items[0].json.result?.ADDRESS_POSTAL_CODE.

Here’s an example

x = {test: 1}
x.nonexistent.test
/* VM527:1 Uncaught TypeError: Cannot read properties of undefined (reading 'test')
    at <anonymous>:1:15
(anonymous) @ VM527:1*/

// Using optional chaining
x.nonexistent?.test
// undefined
1 Like

Hi @pemontto ,
I got the solution above and it’s working well:

What do you think?

2 Likes