JSFiddle - React, Tailwind, and code Playground

by vinodlouis

JavaScript

class Person{
	name = '';
	age = '';

  constructor(name,age){
    this.name = name;
    this.age = age;
  }

  sayHello(){
  	alert(`welcome ${this.name}`)
  }

}

//let var const
//hoisting??
let p1 = new Person("Ankita",21);
//p1name.age..
//-----------------------------
//p1.sayHello();

//let p2 = new Person("Nikita",20);

//p2.sayHello();

Person.prototype.sayHelloWithAge = function(){
  alert(`welcome ${this.name} with age ${this.age}`)
}

p1.sayHelloWithAge();