JavaScript Scope, Closures, and Functional Patterns for Pythonistas (Summary)

Congratulations, you made it to the end of the course! The bouldering gym’s front desk now runs in JavaScript as node front-desk.js. It prints the same seven lines as front_desk.py, from M-101 Ana Reyes: £18.00 to Checked in today: 4, with Learn to Boulder is full right before L-102 Leo Park: £18.00.

The port has no global, no nonlocal and no wall=wall. Each Python line kept its job and became what a JavaScript developer would write.

In this course, you learned how to:

  • Say which variable a name refers to by following the scope chain outward from where the function is written, and when it can be used: a function declaration from the top of its scope, a const or let variable only once its line has run
  • Read old code that uses var, whose variables belong to the whole function, or to the module at the top level, and start as undefined, and change it to let or const when you touch it, then rerun it and check the output
  • Keep state in a closure, with a factory such as makeBandCounter() that returns an arrow or an object of arrows over its own variables
  • Make functions in a loop with for (const wall of WALLS), where each pass gets its own wall
  • Take any number of arguments with a rest parameter such as ...charges, spread an array into a call, and gather extra options with ...extras
  • Pass a callback, give an optional one a do-nothing default, () => {}, and set a timer with setTimeout()
  • Build functions from functions: an arrow that returns an arrow, an arrow that fixes an argument, and pipe() to run steps in order

Keep the Habits That Carry Over

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.