Class ,Object and Constructor in JS

Class ,Object and Constructor in JS

A class can be defined by using a class keyword with any particular name. In JavaScript, the name of the class always starts with an uppercase letter and object is the instance of class through which we can access the member of class.

Constructor is a special type of function which is call by itself whenever an object is created.

Example 1 -Using constructor without argument

<script>

class Demo

{          constructor()

            {

                        console.log(“This class Demo is created”);

            }

}

let object = new Demo();

</script>

Example 2 – Using function without argument

<script>

class Demo

{

Name() {

    console.log(“This class Demo is created via function”);

}

}

let object = new Demo();

object.Name();

</script>

6 thoughts on “Class ,Object and Constructor in JS

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*