Ben Aston Ben Aston - 4 months ago 30
AngularJS Question

What is the benefit of angular.isdefined?

What is the benefit of

over and above
foo === undefined

I can't immediately think of a benefit.


Accessing a truly undefined variable in any way in Javascript, except tyepof throws an error. You can only use Angular.isDefined with properties. E.g, this would work fine:


Because obj is an undefined propery of window.

Examples of the expected behavior:

var foo;
var bar = 42;

typeof foo !== 'undefined'; // false
typeof bar !== 'undefined'; // true
typeof baz !== 'undefined'; // false

angular.isDefined(foo); // false
angular.isDefined(bar); // true
angular.isDefined(baz); // ReferenceError