add a static property to a class in javascript

To add a static property to a class in JavaScript, you can use the static keyword.

Here is an example:

index.tsx
class MyClass {
  static myStaticProperty = 'hello';
}

console.log(MyClass.myStaticProperty); // Output: hello
112 chars
6 lines

In the example above, the myStaticProperty is declared as a static property of the MyClass. This means that the property is not tied to any specific instance of the class, but rather belongs to the class itself.

To access a static property, you can reference the class name followed by the property name (MyClass.myStaticProperty).

gistlibby LogSnag