# tc39/proposal-pattern-matching

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/tc39-proposal-pattern-matching).**

5,782 stars · 90 forks · HTML · MIT

## Links

- GitHub: https://github.com/tc39/proposal-pattern-matching
- Homepage: https://tc39.es/proposal-pattern-matching/
- awesome-repositories: https://awesome-repositories.com/repository/tc39-proposal-pattern-matching.md

## Description

This is a TC39 proposal to add declarative pattern matching syntax to the ECMAScript language. It introduces a `match` expression that allows developers to inspect and branch on data structures using patterns with destructuring, guards, and logical combinators. The proposal defines a custom matcher protocol via a well-known symbol, enabling objects to implement user-defined matching logic with arbitrary extraction and decomposition.

The proposal supports matching against literal primitives using SameValue equality with special handling for signed zero and NaN, as well as relational comparisons and type tests using operators like `instanceof`. Patterns can be combined with `and`, `or`, and `not` operators that evaluate with short-circuit semantics, and guard clauses can attach arbitrary conditions that must be truthy for an arm to match. Destructuring patterns extract and bind values from arrays and objects using positional, named, rest, and optional syntax, with variable bindings scoped via `var`, `let`, or `const`.

The proposal also covers matching in asynchronous contexts, where arms can use `await` and the result is wrapped in a Promise. It includes boolean pattern testing via an `is` operator, regular expression matching with group extraction, and pattern-based exception handling in `catch` clauses. The specification is available as a staged proposal in the TC39 process.

## Tags

### Part of an Awesome List

- [ECMAScript Pattern Matching Proposals](https://awesome-repositories.com/f/awesome-lists/devtools/design-patterns-and-architecture/javascript-implementations/pattern-matching-implementations/ecmascript-pattern-matching-proposals.md) — Proposes native ECMAScript pattern matching syntax with destructuring, guards, and logical combinators.
- [Optional Property Matching](https://awesome-repositories.com/f/awesome-lists/devtools/pattern-matching/optional-structural-matching/optional-property-matching.md) — Allows object patterns to succeed when specified properties are missing via optional markers. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Pattern Guards](https://awesome-repositories.com/f/awesome-lists/devtools/pattern-matching/pattern-guards.md) — Combines pattern matching with conditional guards and logical operators for precise value filtering.
- [Iterable Element Matching](https://awesome-repositories.com/f/awesome-lists/devtools/pattern-matching/variable-length-segment-matching/fixed-length-segment-matches/literal-element-sequence-matches/list-element-structural-matching/iterable-element-matching.md) — Matches iterable values against nested element patterns with optional variable binding. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Regex and Type Guard Matching](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching/regex-and-type-guard-matching.md) — Supports regex matching with group extraction and type guard matching against constructors in patterns.

### Programming Languages & Runtimes

- [Pattern Matching](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-matching.md) — Introduces a match expression that checks values against structural patterns and returns a boolean result. ([source](https://tc39.es/proposal-pattern-matching/))
- [ECMAScript Pattern Matching Proposals](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/javascript-language-features/ecmascript-proposal-polyfills/ecmascript-pattern-matching-proposals.md) — A TC39 proposal introducing pattern matching with literals, objects, arrays, relational operators, and custom matchers.
- [Data Constructor Decompositions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/control-flow/pattern-matching/data-constructor-decompositions.md) — Tests values against constructors and optionally destructures their internal data in pattern arms. ([source](https://tc39.es/proposal-pattern-matching/))
- [Match Guards](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/control-flow/pattern-matching/match-guard-filtering/ast-condition-filters/match-guards.md) — Attaches if conditions to pattern arms that must be truthy for the arm to match, enabling runtime checks.
- [Literal Matching](https://awesome-repositories.com/f/programming-languages-runtimes/literal-matching.md) — Compares values to literal numbers, strings, booleans, null, undefined, or symbols using strict equality. ([source](https://tc39.es/proposal-pattern-matching/))
- [Logical Pattern Combinations](https://awesome-repositories.com/f/programming-languages-runtimes/logical-pattern-combinations.md) — Combines multiple patterns with and, or, or not operators to test a subject against all, any, or none of the sub-patterns. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Object and Array Destructuring](https://awesome-repositories.com/f/programming-languages-runtimes/object-and-array-destructuring.md) — Extracts values from objects by matching named properties against sub-patterns with optional rest syntax. ([source](https://tc39.es/proposal-pattern-matching/))
- [Pattern Bindings](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-bindings.md) — Binds matched sub-values to variables using var/let/const semantics with rest patterns for arrays and objects.
- [Pattern Destructuring](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-destructuring.md) — Extracts and binds values from arrays, objects, and custom extractors using var, let, or const scoping.
- [Match Expression Await Support](https://awesome-repositories.com/f/programming-languages-runtimes/promise-based-flow-control/generator-to-promise-wrappers/async-await-desugaring/match-expression-await-support.md) — Proposes async-aware match expressions with await support inside arms and Promise-wrapped results.
- [Relational Value Comparisons](https://awesome-repositories.com/f/programming-languages-runtimes/relational-value-comparisons.md) — Matches values against relational operators like less-than, greater-than, equality, and instanceof within patterns. ([source](https://tc39.es/proposal-pattern-matching/))
- [Implicit Subject Comparisons](https://awesome-repositories.com/f/programming-languages-runtimes/relational-value-comparisons/implicit-subject-comparisons.md) — Employs binary boolean operators in patterns with the subject as the implicit left-hand side. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Pattern Relational Comparisons](https://awesome-repositories.com/f/programming-languages-runtimes/relational-value-comparisons/pattern-relational-comparisons.md) — Allows relational operators and instanceof checks directly in pattern matching arms. ([source](https://tc39.es/proposal-pattern-matching/))
- [Structural Pattern Matching](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching.md) — Extends language grammar with a match expression that destructures values against nested patterns declaratively.
- [ECMAScript Match Expressions](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching/ecmascript-match-expressions.md) — Proposes a match expression for JavaScript with destructuring, guards, and logical combinators.
- [Variable Bindings](https://awesome-repositories.com/f/programming-languages-runtimes/variable-bindings.md) — Assigns extracted values from matched structures to variables declared within the pattern. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Pattern](https://awesome-repositories.com/f/programming-languages-runtimes/variable-bindings/pattern.md) — Binds extracted values from matched structures to variables using var, let, or const within patterns. ([source](https://tc39.es/proposal-pattern-matching/))
- [Algebraic Data Types](https://awesome-repositories.com/f/programming-languages-runtimes/algebraic-data-types.md) — Matches values against constructors and destructures their internal data in a functional programming style.
- [Unary Sign Matching](https://awesome-repositories.com/f/programming-languages-runtimes/literal-matching/unary-sign-matching.md) — Matches numeric values against unary plus or minus expressions with SameValue zero handling. ([source](https://tc39.es/proposal-pattern-matching/))
- [Property Pattern Matching](https://awesome-repositories.com/f/programming-languages-runtimes/object-property-accessors/property-pattern-matching.md) — Matches object properties against nested patterns with optional value binding. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Async](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-matching/async.md) — Supports pattern matching in async contexts with await inside arms and Promise-wrapped results.
- [Extractor Patterns](https://awesome-repositories.com/f/programming-languages-runtimes/pattern-matching/extractor-patterns.md) — Combines custom matchers with array-like patterns on return values for structured decomposition of matched results. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Pattern-Based Exception Handling](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-exception-handling/pattern-based-exception-handling.md) — Uses pattern matching in catch clauses to conditionally handle exceptions based on type or value. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Array Structure Matching](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching/array-structure-matching.md) — Tests that a subject is iterable with a specific number of items, matching each against sub-patterns. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Iterable Structure Matching](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching/iterable-structure-matching.md) — Matches iterable structures by length, element sub-patterns, and optional rest collection. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Object Structure Matching](https://awesome-repositories.com/f/programming-languages-runtimes/structural-pattern-matching/object-structure-matching.md) — Matches object structures by property presence, sub-patterns, and rest collection. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))

### Software Engineering & Architecture

- [Pattern Combinator Short-Circuiting](https://awesome-repositories.com/f/software-engineering-architecture/boolean-logic-extractors/truthiness-evaluators/short-circuit-operators/pattern-combinator-short-circuiting.md) — Supports and, or, and not pattern combinators with short-circuit evaluation semantics.
- [Type-Aware Matching](https://awesome-repositories.com/f/software-engineering-architecture/pattern-matching-libraries/type-aware-matching.md) — Uses constructor functions or types to test whether a value is an instance of that type in patterns. ([source](https://tc39.github.io/proposal-pattern-matching))
- [When Expression Pattern Matching](https://awesome-repositories.com/f/software-engineering-architecture/conditional-branching/conditional-expression-returns/when-expression-pattern-matching.md) — Evaluates a value against pattern clauses and returns the result of the first matching clause. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Pattern Variable References](https://awesome-repositories.com/f/software-engineering-architecture/stacks/expression-parsing/variable-reference-resolvers/pattern-variable-references.md) — Resolves variable or property paths and tests the subject for SameValue equality with the resolved value. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Built-in Type Guards](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/php-type-checkers/built-in-function-guards/built-in-type-guards.md) — Provides built-in custom matchers for JavaScript primitive types and constructors in pattern matching. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))
- [Remaining Element Retrieval](https://awesome-repositories.com/f/software-engineering-architecture/stream-element-limiting/remaining-element-retrieval.md) — Captures remaining elements of arrays or properties of objects into a single variable during destructuring. ([source](https://tc39.github.io/proposal-pattern-matching))

### Testing & Quality Assurance

- [Protocol-Based](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/test-frameworks/assertions-and-validation/assertion-validation-utilities/snapshot-testing-utilities/custom-matcher-pipelines/custom-matchers/protocol-based.md) — Defines a well-known symbol protocol for user-defined matching logic with arbitrary extraction and decomposition.
- [SameValue Equality with Signed Zero](https://awesome-repositories.com/f/testing-quality-assurance/array-equality-comparison/samevalue-equality-with-signed-zero.md) — Uses SameValue equality for literal primitives with special handling for signed zero and NaN.
- [Pattern Matching Boolean Tests](https://awesome-repositories.com/f/testing-quality-assurance/assertion-macros/boolean-return-assertions/pattern-matching-boolean-tests.md) — Uses the is operator to check a value against a pattern, returning true or false with optional bindings. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))

### User Interface & Experience

- [Pattern Match Combinators](https://awesome-repositories.com/f/user-interface-experience/search-filtering-logic/combinator-logic/pattern-match-combinators.md) — Joins multiple patterns with and, or, or not keywords to require all, any, or none of the sub-patterns to match. ([source](https://cdn.jsdelivr.net/gh/tc39/proposal-pattern-matching@main/README.md))

### Data & Databases

- [Array Element Skipping](https://awesome-repositories.com/f/data-databases/immutable-array-updates/array-element-modifiers/array-element-accessors/array-element-skipping.md) — Skips leading array elements during pattern matching without binding them. ([source](https://tc39.github.io/proposal-pattern-matching))

### Education & Learning Resources

- [Regular Expression Pattern Implementations](https://awesome-repositories.com/f/education-learning-resources/regular-expression-pattern-implementations.md) — Tests strings against regular expressions and extracts matched groups within pattern arms. ([source](https://tc39.github.io/proposal-pattern-matching))
- [Global Regex Matches](https://awesome-repositories.com/f/education-learning-resources/regular-expression-pattern-implementations/global-regex-matches.md) — Supports global regular expression matching with group extraction in pattern arms. ([source](https://tc39.es/proposal-pattern-matching/))
