Categories
JavaScript Answers

How to check if a value is not null and not empty string in JavaScript?

Spread the love

Sometimes, we want to check if a value is not null and not empty string in JavaScript.

In this article, we’ll look at how to check if a value is not null and not empty string in JavaScript.

How to check if a value is not null and not empty string in JavaScript?

To check if a value is not null and not empty string in JavaScript, we can use the !== operator.

For instance, we write

if (data !== null && data !== "") {
  // ...
}

to check if data isn’t null and data isn’t an empty string with

data !== null && data !== ""

Conclusion

To check if a value is not null and not empty string in JavaScript, we can use the !== operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *