JavaScript Class

There are no class concept in JavaScript. But JavaScript uses functions as classes.Defining a class in JavaScript is as easy as defining a function.

Syntax

function Member() { // code block to be executed }

In the example below we define a new class called Member.

Example

<script language="javascript" type="text/javascript" >
function Member() {
    //Properties
    this.name = "Max";
    this.age = "28";
    //functions
    this.sayHello = function() {
        return this.name + " Says Hello";
    }
}
//Creating person instance
var m = new Member();
document.write(m.sayHello());
</script>