Back to JavaScript Notes
Topic #219

JS Class Static

Static members belong to the class itself, not instances. They hold utilities and shared constants.

Static class methods are defined on the class itself.

You cannot call a static method on an object, only on an object class.

Example

class Car {
  constructor(name) {
    this.name =
  name;

  }
  static hello() {
    return "Hello!!";

  }
}

const myCar = new Car("Ford");

// You can call 'hello()' on
  the Car Class:
document.getElementById("demo").innerHTML
  = Car.hello();

// But NOT on a Car Object:
// document.getElementById("demo").innerHTML
  = myCar.hello();
// this will raise an error.

If you want to use the myCar object inside the static method, you can send it as a parameter:

Example

class Car {
  constructor(name) {
    this.name =
  name;

  }
  static hello(x) {
    return "Hello " +
  x.name;

  }
}
const myCar = new Car("Ford");
document.getElementById("demo").innerHTML
  = Car.hello(myCar);

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

JS Class Static – FAQs

Quick answers about learning JS Class Static in JavaScript.

This free note from Coding Now Tech Institute explains JS Class Static in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including JS Class Static, is 100% free with no signup required.
With focused practice, most students grasp JS Class Static in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now