Archive for June 30, 2009

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.

June 30, 2009 at 12:12 pm Leave a comment


Calendar

June 2009
M T W T F S S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

Posts by Month

Posts by Category


Follow

Get every new post delivered to your Inbox.