Class Static Block

Motivation
Class static blocks provide a declarative way to define static fields and static private fields on a class. They are executed before the constructor and can be used to initialize static fields and static private fields.
A class static block is a block of code that is prefixed with the static keyword and is executed when the class is first evaluated. The block is evaluated in the scope of the class and can be used to initialize static fields and static private fields.
class Note {
static lesson = 'JavaScript';
}
class Board extends Note {
static #uniqueItem = 'something'
static blocks = []
static {
this.blocks.push(super.lesson, 'ES2022')
}
static {
this.blocks.push('ES14')
}
static {
this.blocks.push(this.#uniqueItem)
}
}
console.log(Board.blocks) // ['JavaScript', 'ES2022', 'ES14']
Status
This proposal is currently at Stage 4.
Full documentation can be found here.