Khoa Nguyen
Pressure creates diamonds
Skip to main content

JavaScript Advanced Concept Closure

Last updated: 10 May 2024 (7 month ago)

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;
  }
}
  • E-commerce
  • Landing page
  • Usability
  • Accessibility
  • Information Architecture
  • Responsive Design