How to use class with constructor in JavaScript

1 Answer

0 votes
class CClass{
	constructor(name, age) {
    	this.name = name;
      	this.age = age;
    }
  	display() {
    	console.log(this.name + " is " + this.age + " years old");
    }
}

let worker = new CClass("Emma", 31);

worker.display();  




/*
run:

"Emma is 31 years old"

*/

 



answered Sep 16, 2022 by avibootz

Related questions

1 answer 222 views
2 answers 247 views
1 answer 219 views
2 answers 172 views
...