JavaScript static

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

static members live on the constructor function. Call them as Class.method(), not on instances. Subclasses inherit static members.

JavaScript Syntax

JavaScript
class MathUtil {
  static double(n) { return n * 2; }
}
console.log(MathUtil.double(4));
console.log(new MathUtil().double);
Try it Editor

How It Works

  1. Class call. MathUtil.double works.
  2. Instance. No double property on the instance.

Examples

Example 1 — Static fields

Shared class data.

JavaScript
class A { static version = 1; }
console.log(A.version);
Try it Editor

How It Works

  1. Stored on the constructor.

Example 2 — Inherited statics

Child can call parent statics.

JavaScript
class A { static id(){ return "A"; } }
class B extends A {}
console.log(B.id());
Try it Editor

How It Works

  1. Static inheritance along constructors.

Example 3 — this in static

this is the class.

JavaScript
class A { static who(){ return this.name; } }
console.log(A.who());
Try it Editor

How It Works

  1. this refers to A.

Frequently Asked Questions

For helpers tied to the type (factories, constants), not per-instance state.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful