🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #219

JS Class Static

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 CodingNow 2.0'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 CodingNow 2.0 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 CodingNow 2.0, 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 CodingNow 2.0'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 CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now