Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show's what the EcmaScript 5 undefined immutability really means.
(function ( undefined ) {
console.log( '0: ' + undefined );
})( 0 ); // => 0
(function ( undefined ) {
'use strict';
console.log( '1: ' + undefined );
})( 1 ); // => 1
(function () {
undefined = 2;
console.log( '2: ' + undefined );
})(); // => 2
(function () {
'use strict';
try {
undefined = 3;
console.log( '3: ' + undefined );
} catch (e) {
console.log( '3: ' + e );
}
})(); // => TypeError
(function () {
var undefined = 4;
console.log( '4: ' + undefined );
})(); // => 4
(function () {
'use strict';
var undefined = 5;
console.log( '5: ' + undefined );
})(); // => 5
var undefined = 6;
(function () {
console.log( '6: ' + undefined );
})(); // => undefined
var undefined = 7;
(function () {
'use strict';
console.log( '7: ' + undefined );
})(); // => undefined
@gsans

This comment has been minimized.

Copy link

@gsans gsans commented Nov 14, 2014

After checking the gist everything looks fine. #0-2 are not really uses of "undefined" but a parameter using a JavaScript built-in object name which is not recommended but possible. You could also use parameters names like window, document or location with similar results. #4-5 are local variables doing the same as said before. The rest look good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.