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


Picture showing the output of classes in JavaScript



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250