Created
April 10, 2013 16:41
-
-
Save mgol/5356300 to your computer and use it in GitHub Desktop.
Show's what the EcmaScript 5 undefined immutability really means.
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
(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.