Created
February 10, 2020 10:28
-
-
Save harrisonmalone/5aaf67154c0d2908b8670076bd3811d3 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script src="./index.js"></script> | |
</body> | |
</html> |
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
const prepareCake = (flavor) => { | |
return () => { | |
debugger | |
setTimeout(() => console.log(`Made a ${flavor} cake!`), 1000) | |
} | |
} | |
const makeCakeLater = prepareCake('banana') | |
makeCakeLater() | |
// run this project in chrome and ensure you hit the debugger | |
// the prepareCake function takes in one string argument and then returns a function | |
// the returned function is stored in a variable which is then invoked on the next line | |
// the returned function is a closure as it has access to the variables in the outer lexical scope, in this case flavor | |
// you can see this in the closure menu under scope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment