JavaScript static Method

Last Updated : 18 Jun 2026

JavaScript classes allow methods to be defined as static using the static keyword. A static method belongs to the class itself rather than to the objects created from that class.

Unlike regular methods, static methods cannot be called using an object instance. Instead, they must be invoked directly using the class name.

In this chapter, you will learn about JavaScript static methods, their syntax, features, and practical uses.

What is a Static Method?

A static method is a method that belongs to the class itself instead of an instance of the class. Since static methods are associated with the class, they can be called directly using the class name without creating an object.

Static methods are commonly used for utility functions, helper methods, validation functions, and factory methods.

Syntax

A static method is declared inside a class using the static keyword.

class ClassName {
    static methodName() {
        // code
    }
}

Points to Remember

  • The static keyword is used to declare a static method.
  • Static methods belong to the class rather than its instances.
  • Static methods are called using the class name.
  • A class can contain multiple static methods.
  • If multiple static methods have the same name, the last declaration overrides the previous ones.
  • Static methods are commonly used to create utility and helper functions.
  • Inside a static method, the this keyword refers to the class itself.
  • Static methods can call other static methods using the this keyword.
  • Static methods can be inherited by child classes.

How Static Methods Work?

Static methods are attached directly to the class and are not available on object instances. When a static method is called, JavaScript executes it in the context of the class rather than a specific object.

Because static methods do not belong to instances, they cannot directly access instance properties and methods.

JavaScript Static Method Examples

The following examples demonstrate different ways to use static methods in JavaScript classes.

Example 1: Comparing Objects Using a Static Method

This example demonstrates how a static method can operate on multiple objects without belonging to any specific object. The static method compares the properties of two objects and displays the result.

JavaScript

Execute Now

Output:

JavaScript static Method

Example 2: Calling One Static Method from Another

This example demonstrates how one static method can invoke another static method using the this keyword. Since this refers to the class inside a static method, it can be used to access other static properties and methods.

JavaScript

Execute Now

Output:

JavaScript static Method

Example 3: Using a Static Factory Method

This example demonstrates how a static method can be used as a factory method to create and return objects. Factory methods are commonly used to create class instances from JSON data, configuration objects, or other input formats.

JavaScript

Execute Now

Output:

JavaScript static Method

Static Vs. Instance Methods

A static method belongs to the class and is called using the class name, whereas an instance method belongs to an object and is called using an instance of the class. Static methods are typically used for utility operations, while instance methods operate on the data of individual objects.