Handle null is a biggest nightmare for any developers. As I, developer faced this problem multiple time. That’s why I come with the solution. In this article we are discussing two best way to handle null in Typescript.
Typescript is the advanced version of Javascript. Now a days It becomes the necessity of every web developers. And the Null is the common error and we should know the proper way to handle this.
Before moving forward, A funny quotes, I remember on Null pointer exception.
You are the null pointer exception for me…🤣🤣🤣
Well know let’s focus on the two way to handle null in Typescript.
Let’s take an example before moving to the methods:
We have a function named updatePassword with User type of parameter. This function should be run on actual user objects which is non-nullable types.
function updatePassword(user: User) {
//do functionality
}
Now we have to guard our functionality by writing null check if user objects would be null in any case.
Read original artical here.
#tipsoftheday #typescript #programming #null