Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to simplify simple statement in typescript or js

I would like to simplify this expression but don’t know how. There has to be a way to have the same expression without the three conditions.

if ( request.Document != null &&
      request.Document != undefined &&
      request.Document != "" )

Just for context I am talking something similar to c#’s !string.isNullOrEmpty()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

if (request.Document) {
  ...
}

as null, undefined, '' will all return false.

(but [], {} or ' ' will return true)

Check the equality table for more info about other values.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading