Created
September 12, 2017 19:05
-
-
Save taesup/31ab0e36c2669afb561841ca2a537f59 to your computer and use it in GitHub Desktop.
Whiteboarding exercises for hoisting
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
```javascript | |
function example1 () { | |
y = 20; | |
var y = 0; | |
jump(); | |
var jump = function () { | |
y += 15; | |
} | |
jump(); | |
function jump() { | |
y += 25; | |
} | |
jump(); | |
console.log(y); | |
} | |
example1(); | |
function example2() { | |
x = 25; | |
var x = 0; | |
jump(20); | |
function jump(num) { | |
x = 30; | |
} | |
console.log(x); | |
} | |
example2(); | |
function example3() { | |
y = 30; | |
var y = 0; | |
inc(2); | |
y = 5; | |
function inc(num) { | |
y+= num; | |
} | |
console.log(y); | |
} | |
example3(); | |
function example4() { | |
z = 15; | |
z++; | |
dec(5); | |
z++; | |
function dec(num) { | |
z += num; | |
} | |
var z = 0; | |
console.log(z); | |
} | |
example4(); | |
function example5() { | |
x = 20; | |
var x = 0; | |
inc(); | |
inc(); | |
function inc() { | |
x++; | |
} | |
inc(); | |
var inc = function (num) { | |
x += num; | |
} | |
inc(20); | |
console.log(x); | |
} | |
example5(); | |
function example6() { | |
y = 10; | |
var y = 0; | |
power(y, 2); | |
var power = function (a, p) { | |
y = Math.pow(a, p); | |
} | |
function power(a, p) { | |
y = a + p; | |
} | |
power(y, 2); | |
console.log(y); | |
} | |
example6(); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment