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>
Well explained!!!!!!
Thanks Manpreet for following my posts
thanks
Good Explanation given by Shairy Kalra
Thanks peter. Be in touch for latest updates also
Did a great Job sir!!!!