static
In JavaScript, the static keyword marks a class member that belongs to the class itself rather than to its instances. Inside a class body, it declares static methods, fields, and accessors, and it introduces static initialization blocks.
In a static method, field initializer, or block, this refers to the class. Subclasses created with extends inherit static members through the prototype chain, and super reaches the parent’s static members. Static field initializers and static blocks run once, in source order, when the class is evaluated.
Static methods date from ES2015. Static fields, private static members, and static blocks were added in ES2022 and are Baseline Widely available. Like let, static is a strict-mode reserved word. It can’t name a variable in strict mode code, which includes every class body and ES module.
JavaScript static Keyword Syntax
The static keyword marks fields, methods, and initialization blocks in a class body:
class <Name> {
static <field> [= <value>];
static <method>([<parameters>]) {
<statements>
}
static {
<statements>
}
}
The static prefix also combines with private #names, get, set, async, and generator methods. A static block can’t contain await or arguments, and its declarations stay local to the block.
JavaScript static Keyword Examples
Static members belong to the Temperature class itself, not to its instances:
> class Temperature {
… static unit = "Celsius";
… static fromFahrenheit(degrees) {
… return new Temperature(((degrees - 32) * 5) / 9);
… }
… constructor(degrees) {
… this.degrees = degrees;
… }
… }
undefined
> Temperature.fromFahrenheit(212)
Temperature { degrees: 100 }
> Temperature.unit
'Celsius'
> new Temperature(20).unit
undefined
The static method works as an alternative constructor, and the static field holds data for the whole class. An instance reads .unit as undefined, because static members live on the class, not on the Temperature.prototype object that instances inherit from.
A static initialization block runs setup code that a single field initializer can’t express:
> class Weekday {
… static names = ["Mon", "Tue", "Wed"];
… static indexOf = new Map();
… static {
… this.names.forEach((name, index) => this.indexOf.set(name, index));
… }
… }
undefined
> Weekday.indexOf.get("Tue")
1
The block runs after the fields above it, so both already exist.
JavaScript static Keyword Use Cases
- Defining factory methods and alternative constructors
- Grouping utility functions that don’t need an instance
- Storing constants, caches, or counters shared by every instance
- Running one-time class setup in a static initialization block
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 6, 2026