Related Articles

Related Articles

JavaScript | Classes
  • Last Updated : 15 May, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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


Output:

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :