JavaScript Classes review

Posted on Updated on

Some basic notes

// *****START CLASS***********************************************

//The constructor function is called automatically when an instance of the class is created.
// a special method for creating and initializing an object created with a class.
// There can only be one special method with the name “constructor” in a class.
class Person {
constructor (name,age) { //this is a function
// console.log(name,age);
getUserDescription(){return `${} is ${this.age} year(s) old`}

// *****END CLASS***********************************************

var me = new Person(“Andrew”,25); //arguments are passed to constructor function
// console.log(“”,
// console.log(“this.age”, me.age)
var description = me.getUserDescription(); // Andrew is 25 year(s) old


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s