Articles → JavaScript → Static and non-static method in JavaScript

Static and non-static method in JavaScript






Static methods




class StaticMethodClass {
            constructor() { }

            static message() {
                alert("Static method");
            }
        }

 //  Calling static method
StaticMethodClass.message();


Picture showing the output of static method in JavaScript

Click to Enlarge


Non-static methods




 class NonStaticMethodClass {
            constructor() { }

            message() {
                alert("Non Static method");
            }
        }

 // Calling non-static method
var obj = new NonStaticMethodClass();
obj.message();


Picture showing the output of non-static method in JavaScript

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, June 03, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250