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>
Try It
Output
Posted By - | Karan Gupta |
|
Posted On - | Saturday, May 2, 2020 |