Created
April 27, 2011 11:35
-
-
Save aheckmann/944101 to your computer and use it in GitHub Desktop.
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
a = 1; | |
console.error('global', typeof a); // undefined | |
const a; // const a is hoisted and set to undefined here first | |
a = 2; // has no affect | |
console.error('global after', typeof a); // still undefined | |
//const a = 1; // "TypeError: const 'a' has already been declared" | |
function whoo () { | |
const a = 2; // new execution context so this works | |
console.error('whoo', a); // 2 | |
;(function inner () { | |
a = 3; // silently ignored | |
console.error('inner', a); // 2 | |
})() | |
} | |
whoo(); |
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
a = 1; | |
console.error('global', typeof a, a); // number, 1 | |
var a; // var a is hoisted and set to undefined here first | |
a = 2; | |
console.error('global after', typeof a, a); // number, 2 | |
var a = 1; | |
console.error('global after', typeof a, a); // number, 1 | |
function whoo () { | |
var a = 2; // new execution context | |
console.error('whoo', a); // 2 | |
;(function inner () { | |
a = 3; | |
console.error('inner', a); // 3 | |
})() | |
} | |
whoo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment