Articles → JavaScript → Class Expression In Javascript

Class Expression In Javascript






Class Expressions





Types Of Class Expressions




  1. Named
  2. Unnamed

Example


<html><head><title>Class Expression Demo</title><script>
	// Named
	const myclass1 = class MyClass1 {
		message1() {
			alert("Myclass1");
		}
	}
	new myclass1().message1();
	//  Unnamed
	const myclass2 = class {
		message2() {
			alert("Myclass2");
		}
	}
	new myclass2().message2();
	</script></head><body></body></html>



Output


Picture showing the output of class expression in JavaScript


Picture showing the output of class expression in JavaScript



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250