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



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



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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250