-2

I'm working on an Angular 11 project and I'm struggling with checking for null and undefined.

I have three strings - equipmentId, roomId and personnelId and a flag (boolean) adresseeChosen.

I want the adresseeChosen to be true if at least one of the above strings is not null / undefined, this is my code

this.adresseeChosen= (this.equipmentId != null && this.equipmentId != undefined)  
                      || (this.roomId != null && this.roomId != undefined) 
                      || (this.personnelId != null && this.personnelId != undefined) 

What's the short way of writing this? Thanks!

4

1 Answer 1

2

You can write an utility function to check value is null or undefined. For example:

export function isNullUndefined(value): boolean {
  return (value === null) || (value === undefined);
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is a possible solution: stackoverflow.com/a/36125081/7921804

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.