Created
July 6, 2011 02:50
-
-
Save eliperelman/1066444 to your computer and use it in GitHub Desktop.
Comparing against undefined
This file contains 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 value; | |
// Antipattern: | |
if (value === undefined) { | |
// code here | |
} | |
// Good pattern: | |
(function (undefined) { | |
if (value === undefined) { | |
// code here | |
} | |
})(); | |
// Better pattern: | |
if (typeof value === 'undefined') { | |
// code here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment