Ben Aston Ben Aston - 1 year ago 160
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.

Answer Source

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