Back to Basics: Mastering State Management in Vanilla JavaScript

asierr.dev
8 min readDec 11, 2023

In our continuing “Back to Basics” series, where we unravel fundamental web development concepts, let’s shift our focus to an often framework-associated topic: state management. While frameworks like React, Vue, and Angular provide their own systems for managing state, understanding how to handle state in vanilla JavaScript is a foundational skill that every developer should possess. This article will guide you through the principles of state management in plain JavaScript, showcasing how you can effectively manage, update, and share state across your application without relying on external libraries or frameworks.

1. Understanding State in JavaScript

In web development, ‘state’ refers to the data that changes over time in your application. It’s the dynamic part of your app that differs from the static HTML and CSS. State can be as simple as a text value in an input box or as complex as a collection of data retrieved from a server. In vanilla JavaScript, managing state means keeping track of these changes and ensuring they are reflected in the UI.

Simple State Example: A Counter Application

Consider a basic counter application. The state, in this case, is the current count — a number that changes when a…

--

--