Skip to content

Instantly share code, notes, and snippets.

@fabriziomoscon
Last active December 15, 2015 18:29
Show Gist options
  • Save fabriziomoscon/5304084 to your computer and use it in GitHub Desktop.
Save fabriziomoscon/5304084 to your computer and use it in GitHub Desktop.
JavaScript difference between null, undefined and false in conditions
var isDefined = function (variable) {
if (variable) {
console.log( '=> ' + variable + ' defined' );
} else {
console.log( '=> %s \x1B[0;31mnot defined\x1B[0m', variable );
}
}
var list = [new Date, [], {}, function(){}, 1.1, 'not-empty', true, '', NaN, false, undefined, null];
for (var i = 0; i < list.length ; i++) {
isDefined(list[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment