Search code examples
yuijavascriptjavascript-framework

Why do YUI’s Y.Lang.isNull() and Y.Lang.isUndefined() exist?


From time to time I come across JavaScript library/framework features, where I ask myself: why do we need this if there is a simple cross-browser solution already?

Y.Lang.isNull(bla) and bla === null look equal to me, while the latter is even more beautiful (same applies for “undefined”).

I don’t like it if there are several ways to do the same, without a single comment in the documentation on top.

I’m porting a pure JavaScript file to YUI, and later maybe to another framework and I’m asking myself: should I touch that line every time to look more framework-ish or just leave it alone? Is there any benefit?


Solution

  • For null or undefined, you should go ahead and use a standard JS check for this. A slightly longer explanation is here: Y.Lang.isUndefined vs typeof undefined, which is better and why?