How to create a Javascript class in ES6?

devquora
devquora

Posted On: Feb 22, 2018

 

In Es6 you can create a class using the Class keyword.Below is sample javascript class in ES6.
class User{
    constructor(name,age) {
        this.name  = name;
        this.age = age;
    }

    getData() {
        console.log(this.name + " is " + this.age + " years old !");
    }
}

var user = new User("foo", 7);
s1.getData();

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    ES6 Interview Questions

    What is ES6?

    Es6 or ECMASCRIPT 2015 is sixth major release of ECMAScript language which comes with a lot of new features and syntax..

    ES6 Interview Questions

    List some new features of ES6

    New Features in ES6. Support for constants (also known as “immutable variables”) Block-Scope support for both varia..

    ES6 Interview Questions

    What is Babel?

    Babel is one of the most popular JavaScript transpilers and becomes the industry standard. It allows us to write ES6 cod..