Skip to content

Instantly share code, notes, and snippets.

Last active Nov 22, 2016
What would you like to do?
Underscore.js isDefined mixin
// Underscore.js isDefined mixin
// Returns true if value is defined.
isDefined: function(reference) {
return !_.isUndefined(reference);
/* Example:
var obj = {
definedProperty: 10
=> true
=> false
Copy link

turbobabr commented Apr 20, 2014

I wrote this function because I personally hate the if(!_.isUndefined(....)) {} expression. I believe that isDefined() is more clear for a reader. Have no idea why it's missing in Underscore framework itself. Inspired by angular.isDefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment