Khoa Nguyen
Pressure creates diamonds

JavaScript Advanced Concept Closure

Last updated:

Quick warning

This is hard

Closures

A closure is a function that has access to the parent scope, even after the parent function has closed. JS will automatically store the state of a closure in the heap memory, even after the parent function has returned. This behavior makes them useful for encapsulating private variables.

function encapsulatedState(x) {
  let state = 10;
  return function() {
    state += x;
    return state;
  }
}
  • Design Thinking
  • Usability
  • Accessibility
  • Information Architecture
  • Wireframe
  • Responsive Design