Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created February 10, 2020 10:28
Show Gist options
  • Save harrisonmalone/5aaf67154c0d2908b8670076bd3811d3 to your computer and use it in GitHub Desktop.
Save harrisonmalone/5aaf67154c0d2908b8670076bd3811d3 to your computer and use it in GitHub Desktop.
<!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>
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