JavaScript Static Methods

The static keyword is basically used to create a static property or method of the class. Javascript static methods and properties of a class can’t be called through a class instance. It is called directly from the class.

How To Create Static Method

A Javascript static method can be created by using static keyword followed by static method name and then curly braces {}. Write static method statements inside the curly braces.

General Syntax
      class className(){
   static methodName(){
      //method body
   }
}
    
Try it now

Source Code

          
            class Person {
static personInfo() {
 document.write('I am a static method');
  }
}
Person.personInfo();          
        
Try it now

Static Property

Static property can be created using static keyword followed by the variable name.

General Syntax
      class ClassName{
  static staticPropertyName = "static property value";
}
    
Try it now

Source Code

          
            class Person {
  static workinField = "developer";
}
document.write(Person.workinField);          
        
Try it now

Web Tutorials

Javascript Static Method
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4