Created
May 11, 2019 09:39
-
-
Save thakursaurabh1998/88010f894102d136caac6ad7f151adf4 to your computer and use it in GitHub Desktop.
closure example
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 fib() { | |
let a = 0; | |
let b = 1; | |
let c; | |
return function() { | |
c = a + b; | |
a = b; | |
b = c; | |
return c; | |
} | |
} | |
const f = fib(); | |
for (let i = 0; i < 20; i++) { | |
console.log(f()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment