Category: closures

JavaScript Scope and Closures

Scopes and closures are important in JavaScript. But, they were confusing for me when I first started. Here’s an explanation of scopes and closures to help you understand what they are. Let’s start with scopes. Scope A scope in JavaScript defines what variables you have access to. There are two kinds of sc...

JavaScript Design Patterns: The Singleton

In this article, we’ll dig into the best way to implement a singleton in JavaScript, looking at how this has evolved with the rise of ES6. Among languages used in widespread production, JavaScript is by far the most quickly evolving, looking less like its earliest iterations and more like Python, with every new spec ...

Quick Tip: Master Closures by Reimplementing Them from Scratch

This article was peer reviewed by Tim Severien and Michaela Lehr. Thanks to all of SitePoint’s peer reviewers for making SitePoint content the best it can be! To say there are a lot of articles about closures would be an understatement. Most will explain the definition of a closure, which usually boils down to a ...