Last active
December 15, 2015 18:29
-
-
Save fabriziomoscon/5304084 to your computer and use it in GitHub Desktop.
JavaScript difference between null, undefined and false in conditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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