JSFiddle - React, Tailwind, and code Playground

HTML

<div>

</div>

JavaScript

// Using this inside function
function Student1(first,last) {
	this.firstName = first;
  this.lastName = last;
  this.display = function(){
  	return this.firstName + " " + this.lastName;
  };
}

const harry = new Student1("Harry", "Potter");

document.querySelector("div").innerHTML = harry.display();

document.querySelector("div").innerHTML += "<br>";


// Returning object
function Studen2(first,last){
	return {
  	firstName: first,
    lastName: last,
    display(){
    	return this.firstName + " " + this.lastName;
    }
  };
}

const ron = new Student1("Ron", "Weasley");

document.querySelector("div").innerHTML += ron.display();