Categories
JavaScript Answers

How to check something is empty in JavaScript?

Spread the love

Sometimes, we want to check something is empty in JavaScript.

In this article, we’ll look at how to check something is empty in JavaScript.

How to check something is empty in JavaScript?

To check something is empty in JavaScript, we can check the variable for null, undefined, or an empty string.

For instance, we write

if (myVar === "") {
  // ...
}

to check if myVar is an empty string.

We write

if (myVar === null) {
  // ...
}

to check if myVar is null.

And we write

if (myVar === undefined) {
  // ...
}

to check if myVar is undefined.

Conclusion

To check something is empty in JavaScript, we can check the variable for null, undefined, or an empty string.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.