# Prefer Immutable Data Patterns in JavaScript

Ensure immutability in JavaScript code by using spread operators and non-mutating array methods to avoid shared state mutation issues. This skill helps identify and fix in-place mutations, ensuring each data version is a separate object for better debugging and state management.

**Canonical URL:** https://skillshunter.net/skills/github-thedaviddias-front-end-checklist-skills-immutable-patterns-7a49b74e71fb

**JSON URL:** https://skillshunter.net/api/public/v1/skills/github-thedaviddias-front-end-checklist-skills-immutable-patterns-7a49b74e71fb

**Markdown URL:** https://skillshunter.net/skills/github-thedaviddias-front-end-checklist-skills-immutable-patterns-7a49b74e71fb.md

**Instructions download URL:** https://skillshunter.net/skills/github-thedaviddias-front-end-checklist-skills-immutable-patterns-7a49b74e71fb/download

**Category:** Software & Development

**Source URL:** https://github.com/thedaviddias/Front-End-Checklist/blob/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e/skills/immutable-patterns/SKILL.md

**Source commit:** e8d14d049010e2ce25afcd5e8609dfcbbe63e47e

**Listing approved at:** 2026-11-23

**Created at:** 2026-11-22T16:33:36.000000Z

**Updated at:** 2026-11-23T04:55:22.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Ensure the codebase uses Object.freeze() for configuration objects and avoids direct property assignments on function parameters. The first deliverable is a list of mutated objects and arrays with suggested fixes using spread operators and non-mutating methods.

### When to use it

- Reviewing JavaScript code for shared state mutation issues
- Debugging state management problems in Redux or Zustand
- Ensuring immutability in configuration objects

## Skill instructions

---
name: immutable-patterns
description: "Use when reviewing scripts, client components, bundles, or runtime behavior related to Prefer immutable data patterns. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug."
metadata:
  category: javascript
  priority: medium
  difficulty: intermediate
  estimatedTime: "20"
  source: frontendchecklist.io
  url: https://frontendchecklist.io/rules/javascript/immutable-patterns
---

# Prefer immutable data patterns

Mutating shared objects makes it impossible to track where a value changed. When you update state immutably, each version of the data is a separate object — you can compare references to detect changes, time-travel debug, and know exactly which part of your code changed the data.

## Quick Reference

- Use spread (...) to create modified copies of objects and arrays
- Prefer map(), filter(), and reduce() over push(), splice(), and direct assignment
- Use Object.freeze() for configuration objects that should never change
- Immutability is especially important in state management (Redux, Zustand, Signals)

## Check

Find all places in this code where objects or arrays are mutated in place. Flag direct property assignments on function parameters and push/splice on arrays.

## Fix

Replace in-place mutations with immutable patterns using spread operators and non-mutating array methods.

## Explain

Explain immutable data patterns, why mutation causes bugs in shared state, and how spread and array methods enable immutability.

## Code Review

Review scripts, client components, and browser execution paths related to Prefer immutable data patterns. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.

---

For full implementation details, code examples, and framework-specific guidance,
see `references/rule.md`.

Rule page: https://frontendchecklist.io/rules/javascript/immutable-patterns

