Created
November 24, 2019 00:16
-
-
Save adeelibr/c764d9ca1e2d12b5f41407eb5a80d893 to your computer and use it in GitHub Desktop.
hoisting.js
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
// ### EXAMPLE 1 | |
// -- what you type | |
// var name = 'adeel'; | |
// var profession = 'developer'; | |
// console.log(name + ' ' + profession); | |
// -- what the machine does | |
// var name; // undefined | |
// var profession; // undefined; | |
// name = 'adeel'; | |
// profession = 'developer'; | |
// console.log(name + ' ' + profession); | |
// ### EXAMPLE 2 | |
// -- what you type | |
// a = 2; | |
// var a; | |
// console.log( a ); | |
// -- what the machine does | |
// var a; | |
// a = 2; | |
// console.log(a); | |
// ### EXAMPLE 3 | |
// -- what you type | |
// console.log( a ); | |
// var a = 2; | |
// -- what the machine does | |
// var a; // undefined; | |
// console.log(a); | |
// a = 2; | |
// ### EXAMPLE 4 | |
// -- what you type | |
// foo(); | |
// function foo() { | |
// console.log( a ); // undefined | |
// var a = 2; | |
// } | |
// var result = 1; | |
// console.log(result); | |
// -- what the machine does; | |
// function foo() { | |
// var a; // undefined; | |
// console.log(a); | |
// a = 2; | |
// } | |
// foo(); | |
// var result; | |
// result = 1; | |
// console.log(result); | |
// ### EXAMPLE 5 | |
// -- what you type | |
// foo(); | |
// var foo = function bar() { | |
// console.log('hello'); | |
// }; | |
// what the machine does; | |
// var foo; // undefined; | |
// foo(); // not ReferenceError, but TypeError! | |
// foo = function bar() { | |
// console.log('hello'); | |
// } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment