DEV Community

Tony Mezzolesta
Tony Mezzolesta

Posted on

1 1

The Power of Null

Every programmer that has some sort of social media presence has seen this image:

Null

This is the perfect analogy of Null. With this in mind, you can actually utilize the use of Null. Null is actually a value to represent the absent of a value in a data type. The complete absence of a value is called a bottom type but that

"To Null or not to Null":

In most of my SQL tables, I always have a [DELETE_DATE] field. This is because I do not like to actually DELETE a record from a table. Instead, I will fill in a date (CURRENT_TIMESTAMP for MSSql).

This is where Null becomes important to my SQL environment. All of my stored procedures will always check to see if a date has been put into the [DELETE_DATE] field.

Another example in my SQL environment is using this to activate certain processes. I have a service that runs through different events based on statuses and dates. I will use a [PROCESS_DATE] to confirm that the record has been processed. You can utilize this field in order to "re-trigger" and event by putting a Null value on [PROCESS_DATE] for the record. The service will see this record and run the process again.

In JavaScript, the use of Null is also valuable (yes that was a pun). It's the best way to check for elements of an object to see if they exist. Especially when getting responses from APIs/Document DBs/and callbacks.

if(object.element) is the same as if(object.element === null). Any time code can be shortened and compressed is a plus in any programmers book.

I hope this sheds some light on the power of Null and its use as a value even though it represents the absence of a value... if that made any sense.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay