Expressions and patterns

Setter syntax

Try the free JavaScript compiler

Defines a function invoked on ordinary assignment, with exactly one formal parameter. Its return value is not the value of the assignment expression.

Formal Syntax & Structure

javascript syntaxjavascript
set name(value) { /* update state */ }

Working Example

Example Snippetjavascript
const o={n:0,set value(x){this.n=x+1;}};o.value=4;console.log(o.n);
JavaScript Reference