Skip to content

Static Members

Static members (also called class-level members) belong to the class itself, not to individual instances. They are shared across all instances and can be accessed without creating an object.


ConceptAnalogy
Instance membersEach student’s name, grades, locker number
Static membersSchool name, total enrollment, bell schedule
Static methodCalculate GPA formula (same for all students)

class Configuration {
static appName = "MyApp";
static version = "1.0.0";
static #apiKey = "secret-key-123"; // Private static!
static getAppInfo() {
return `${Configuration.appName} v${Configuration.version}`;
}
}
console.log(Configuration.appName); // "MyApp"

AspectStatic MembersInstance Members
Belongs toThe classThe instance
AccessClassName.memberobject.member
MemoryOne copy sharedCopy per instance
Can access instance data?NoYes

  • Constants (MAX_SIZE, PI)
  • Factory methods (Promise.resolve())
  • Utility functions (Math.round())
  • Counters (track number of instances)
  • Overuse of static methods (procedural code in OOP clothing)
  • Global mutable state

Previous Topic: Access Modifiers → Next Topic: Interfaces →