Static Properties in JavaScript

Static properties in JavaScript belong to the class itself rather than its instances. They can be accessed directly on the class without creating objects, making them useful for storing class-level data like constants or shared values.

Syntax

// Function constructor approach
function ClassName(params) {
    // instance properties
}
ClassName.staticProperty = value;

// ES6 class approach
class ClassName {
    static staticProperty = value;
}

Example: Static Properties with Function Constructor




    
    
    Static Properties Example


    
    
    


Example: Static Properties with ES6 Classes




    
    
    ES6 Static Properties


    
    
    


Comparison: Static vs Instance Properties

Property Type Access Method Shared Across Instances Memory Usage
Static ClassName.property Yes Single copy
Instance instance.property No Copy per instance

Common Use Cases




    
    
    Static Properties Use Cases


    
    
    


Key Points

  • Static properties belong to the class, not instances
  • Accessed using ClassName.property syntax
  • Useful for constants, counters, and shared data
  • Memory efficient - only one copy exists
  • Cannot be accessed through instance objects

Conclusion

Static properties provide a way to store class-level data that is shared across all instances. They are perfect for constants, utility values, and maintaining class-wide state like counters.

Updated on: 2026-03-15T23:18:59+05:30

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements