Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if an object is null or undefined in angular 2

Tags:

angular

I have 2 object, one takes person details and other one takes address details via form. And each object has 3 fields. Now, before I send this to my parent, I need an check if condition these 2 objects are not undefined or null

I have tried these conditions and all fail:

=> !(this.person)&&!(this.address)

=> this.person !=(null || undefined)

I know that I can also compare each property of the object to null or undefined but can't write 6 conditions, because it breaches coding standards.

So guys please help me with this

like image 339
Hafeez Avatar asked May 06 '26 00:05

Hafeez


1 Answers

Its not really and Angular things its more to do with Javascript. A double equal to null will return true if its null or undefined.

if (someValue == null) {
 // Do something if null or undefined
}

This table should help.

enter image description here

like image 182
Thomas Avatar answered May 07 '26 15:05

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!