Articles → JavaScript → Class expression in JavaScript

Class expression in JavaScript






Class expressions





Types of class expressions









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

Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250