Statements are Dead.
Long Live Expressions.
For 25 years, we've wrestled with switch case fallthroughs and nested if/else pyramids.
The Pattern Matching proposal is finally here to bring structural matching to JavaScript, turning complex imperative checks into declarative, value-returning expressions.
02. The Match Syntax
Unlike switch, the match construct is an expression. It returns a value. It matches based on the shape and content of data, not just equality.
The Basic Structure
const result = match (response) {
{ status: 200, data } => handleSuccess(data),
{ status: 404 } => handleError("Not Found"),
{ status: 500 } => retryRequest(),
_ => handleUnknown()
};
03. Switch vs. Match
The Old Way (Switch)
- Verbose
breakstatements needed. - Accidental fallthrough bugs.
- Not an expression (cannot assign result directly).
- Only matches primitive values strictly.
The New Way (Match)
- Concise, arrow-function syntax.
- Exhaustive checking (ensures all cases covered).
- Returns a value automatically.
- Matches object shapes, arrays, and types.
Real-World Refactor: User Reducer
Legacy (Switch)
function reducer(state, action) {
switch (action.type) {
case 'FETCH_SUCCESS':
return {
...state,
loading: false,
data: action.payload
};
case 'FETCH_ERROR':
return {
...state,
loading: false,
error: action.error
};
default:
return state;
}
}
Modern (Match)
const reducer = (state, action) => match (action) {
{ type: 'FETCH_SUCCESS', payload } => ({
...state,
loading: false,
data: payload
}),
{ type: 'FETCH_ERROR', error } => ({
...state,
loading: false,
error
}),
_ => state
};
04. Redux Reducers Reimagined
One of the best use cases for Pattern Matching is in state reducers. Gone are the days of massive switch statements with block scoping issues.
With match, reducers become pure data transformation pipelines that are easier to read and test.
05. The Senior Engineer's Perspective
Is it ready for production?
As of 2026, Pattern Matching is Stage 4 and fully supported in modern Node.js and browsers. However, for library authors, continue to transpile or offer fallbacks if you validly support legacy environments (though you shouldn't need to support IE11 anymore!).
Drastically reduces cognitive load. Makes state machines first-class citizens.
New syntax learning curve for junior devs. Debugging match failures can be tricky initially.