isNullOrEmpty

Coding a lot in JavaScript i often have to check if an object is

undefined, null or at least an empty string.

So it would be great to have a method like in C#

string.isNullOrEmpty()

This is my solution for JavaScript:

window.isNullOrEmpty = function(obj) {
return (obj === '' || obj === null || obj === undefined)
}

And the best of it: it does not only work on strings like in C#, it works for every object.

Attatching the method to the window object makes it purely available from everywhere.

Advertisements
This entry was posted in javascript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s