Created
March 1, 2012 22:23
-
-
Save easierbycode/1953667 to your computer and use it in GitHub Desktop.
undefined is mutable
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
// In JavaScript, undefined is nothing but a global variable name without a default value. Therefore, its primitive value is undefined. You can change the value of undefined: | |
var a = {}; | |
a.b === undefined; // true because property b is not set | |
undefined = 42; | |
a.b === undefined; // false | |
// Due to the mutability of undefined, it is generally a better idea to check for undefined-ness through typeof: | |
var a = {}; | |
typeof a.b == 'undefined'; // always true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment