Articles → JavaScript → Classes in JavaScript

Classes in JavaScript






How to create a class?




<html>

<head>
	<title>Classes in JavaScript</title>
	<script>
	class Person {
		constructor() {}
		messageme() {
			alert("Hi Gyan");
		}
	}
	class PersonWithParam {
		constructor(message) {
			this.message = message;
		}
		messageme() {
			alert("hello " + this.message);
		}
	}
	person = new Person();
	person.messageme();
	personWithParam = new PersonWithParam("Gyan");
	personWithParam.messageme();
	</script>
</head>

<body> </body>

</html>





Output


Picture showing the output of classes in JavaScript

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, May 02, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250