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.