Introduction of new version of JavaScript (ES6) introduced the use of classes instead of functions.Classes are similar to functions.They use class keyword instead of function keyword.
They use constructor method to initialise.
Syntax:
class classname {
constructor(parameter) {
this.classname = parameter;
}
}
Below example illustrates the JavaScript classes:
<!DOCTYPE html> <html> <body> <center> <h1 style="color: green;"> GeeksforGeeks </h1> <p> A Computer Sciecne Portal for Geeks </p> <b>JavaScript Classes</b> <p id="demo"></p> <script> class class_name { constructor(value) { this.classes = value; } } myvalue = new class_name("GeeksforGeeks"); document.getElementById("demo").innerHTML = myvalue.classes; </script> </center> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- How to remove all classes that begin with a certain string in JavaScript?
- JavaScript | Nested Classes
- Private Classes in Ruby
- PHP | Classes
- Understanding Classes and Objects in Java
- C# | Abstract Classes
- Wildcard Selectors (*, ^ and $) in CSS for classes
- Abstract Classes in PHP
- CSS | Pseudo-classes
- Abstract Classes in Python
- jQuery | Get and Set CSS Classes
- jQuery | multiple classes Selector
- Classes in TypeScript
- Use of :even and :odd pseudo-classes with list items in CSS
- Generic Classes in Scala
- When to use static vs instantiated classes in PHP?
- Type Aliases vs Inline Classes
- How to Add and Remove multiple classes in jQuery ?
- Perl | Classes in OOP
- Kotlin Sealed Classes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


