Horje
What are Classes in ES6 ?

Classes are the basic building blocks of Object Oriented Programming in any language. In JavaScript, the concept of classes was introduced in ES6 or EcmaScript 2015 with the introduction of the OOPs concept. The JavaScript classes can be used to encapsulate the properties and methods that can be used by creating instances of these classes. A class can be created using the class keyword. It can contain multiple properties and methods using an access specifier to specify their access. The access specifiers can be used as Public, Private, and Protector.

Example: The below code example will show how you can create classes in JavaScript.

Javascript

class demoClass {
    constructor(name, desc) {
        this.name = name;
        this.desc = desc;
    }
    getData() {
        return {
            name: this.name,
            desc: this.desc
        }
    }
}
const obj =
    new demoClass("GeeksforGeeks",
        "A Computer Science Portal.");
const { name: resObjName, desc: resObjDesc } =
    obj.getData();
console.log(
    "Company Name: ",resObjName,", Description: ",resObjDesc);

Output

Company Name:  GeeksforGeeks , Description:  A Computer Science Portal.



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How do we use the encodeURIComponent() function in JavaScript ? How do we use the encodeURIComponent() function in JavaScript ?
How does the JSON.parse() method works in JavaScript ? How does the JSON.parse() method works in JavaScript ?
How the Array.unshift() method works in JavaScript ? How the Array.unshift() method works in JavaScript ?
How to Get a Value from a JSON Array in JavaScript ? How to Get a Value from a JSON Array in JavaScript ?
TypeScript Array entries() Method TypeScript Array entries() Method

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12