Created
June 13, 2012 19:43
-
-
Save rwaldron/2926029 to your computer and use it in GitHub Desktop.
null is not 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
// http://traceur-compiler.googlecode.com/git/demo/repl.html | |
// open the console | |
// paste this into the text area. | |
// | |
// or | |
// | |
// Run in Firefox 15 (Nightly) | |
function nullIsNotUndefined( arg = "foo" ) { | |
return arg; | |
} | |
console.log( nullIsNotUndefined() === "foo" ); | |
console.log( nullIsNotUndefined(null) === null ); |
The end result is, undefined
and null
have been spec'ed as having very similar behavior. Their main difference is in their meaning. The standard library uses null
very sparingly, but quite frankly each of its use could be replaced by undefined
without losing anything.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Technically,
undefined
isn't writable or configurable either, but unfortunately implementation adherence isn't consistent