Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created June 13, 2012 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwaldron/2926029 to your computer and use it in GitHub Desktop.
Save rwaldron/2926029 to your computer and use it in GitHub Desktop.
null is not undefined.
// 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 );
@espadrine
Copy link

It does make sense, but it also means that the difference between undefined and null is only semantic.

(That, and the fact that you cannot assign null.)

@rwaldron
Copy link
Author

Technically, undefined isn't writable or configurable either, but unfortunately implementation adherence isn't consistent

@espadrine
Copy link

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