Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript static class variable

class ClassWithStaticMethod {
  static staticProperty = 'someValue';
  static staticMethod() {
    return 'static method has been called.';
  }
  static {
    console.log('Class static initialization block called');
  }
}

console.log(ClassWithStaticMethod.staticProperty);
// output: "someValue"
console.log(ClassWithStaticMethod.staticMethod());
// output: "static method has been called."

//------------------syntex-------------------------

static methodName() { /* ... */ }
static propertyName [= value];

// Class static initialization block
static {

}
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #static #class #variable
ADD COMMENT
Topic
Name
2+1 =