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

Congratulations, the gym’s front desk now runs in JavaScript! node front-desk.js 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 before L-102 Leo Park: £18.00.

In this course, you learned how to:

  • Identify what a name refers to and when you can use it: a function declaration from the top of its scope, a let or const once its line has run
  • Read old var code, whose variables belong to the whole function or module and read undefined until assigned, then switch to let or const and rerun
  • Keep state in a factory, returning an arrow or an object of arrows such as { next, issued }
  • Make functions in a loop with for (const wall of WALLS), which gives each pass its own wall
  • Take any number of arguments with ...charges, spread an array into a call, and gather extra options with ...extras
  • Pass callbacks, give an optional one a () => {} default, and set timers with setTimeout()
  • Build functions from functions: fix a rate once with makeDiscount(0.2), fix an argument as withShoeHire() does, and run steps in order with pipe()

Know Where the Python Analogies Stop

Lookup still runs outward from where the code is written, as in LEGB, with blocks as extra scopes. Closures still keep the enclosing call’s variables, and you still put constants first and calls last. Other analogies stop partway:

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.