Show alert with javascript prototype

Every object in javascript has the prototype property which we can attach a new function or property to it. Below javascript program will show two alert boxes once you have loaded the webpage.

function helloWorld() {
	alert("Hello World!")

helloWorld.prototype.helloAgain = function(name) {
					alert("Hello " + name);
var helloTwice = new helloWorld();


We first create a function named helloWorld then we added another function (which will show the name of a person) to helloWorld’s prototype. Next we create an object which owns all the properties of helloWorld then pass in the name of a person which will be used by the helloAgain function. The “Hello World!” alert will show first follows by the second alert in the helloAgain function.

hello world

hello john

Show alert with javascript prototype program is super simple, isn’t it?