The static keyword defines the static methods or properties for a class. These methods and properties are called in the class itself.

class Car {
  constructor(name) { = name;
  static hello(x) {
    return "Hello " +;
let myCar = new Car("Toyota");

console.log(myCar.hello()); // This will throw an error
// Result: Hello Toyota

One can access the static method or property of another static method of the same class using this keyword.

results matching ""

    No results matching ""