Y.Lang.isUndefined vs typeof undefined, which is better and why?


I was wondering why YUI libs use Y.Lang.isUndefined() even when JS has a built in feature to check type of a variable.

The reason that method exists is for API consistency -- the YUI team felt it would be weird to leave it out. As LightStyle points out, isUndefined() doesn't do anything special, so you probably shouldn't use it unless you really like the aesthetics.

In fact, only a few of the YUI type checking methods do any actual useful work beyond what you could do natively. Ryan Grove has a detailed walkthrough of these methods (and why you should avoid most of them) in his talk, When Not To Use YUI (youtube.com)


There is no a true reason in my opinion, it was only for development purposes(it is easier to call a function insted of writing typeof myVar === 'undefined').

L.isUndefined = function(o) {
    return typeof o === 'undefined';
};

From YUI.js source - row 1973