Created
February 3, 2022 15:37
-
-
Save alexshelkov/f1db00c8ca82c3c72806f4deeab0516d to your computer and use it in GitHub Desktop.
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
// file scope | |
var a; // declaration of 'a' moved on top of the file and split from assignment | |
console.log(a); // so here 'a' is undefined, but declared, | |
// so it does not throw an error | |
a = 1; // now 'a' is assigned to 1 | |
console.log(a); | |
function f1() { // f1 scope | |
var b; // 'b' moved here | |
console.log(a); | |
console.log(b); | |
b = 1; | |
console.log(b); | |
// TODO: try uncomment | |
// console.log(x); | |
} | |
function f2() { // f2 scope | |
function x() { // functions declarations are also moved on top, | |
// that is why we have access to x() anywhere inside f2() | |
console.log('x'); | |
} | |
console.log(x()); | |
// function x() { ... } is moved to the top | |
console.log(x()); | |
// TODO: try uncomment | |
// console.log(b); | |
} | |
f1(); | |
f2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment