How does JavaScript .prototype work?

JavascriptWeb DevelopmentFront End Technology

The objects in JavaScript inherit the properties and methods from their prototype. We generally create one with new Object(), which also gets inherit from Object.prototype. In the same way, objects with new Date() inherit Date.prototype.


<!DOCTYPE html>
      <h2>Department Details</h2>
      <p id="details"></p>
         function Department(myid, name, section) {
   = myid;
   = name;
            this.section = section;
         var myDept = new Department("AKD", "Marketing", "North");
         document.getElementById("details").innerHTML =
            "The name and section of the Department is " + + " and "
            + myDept.section+ " respectively.";
Published on 31-Jan-2018 12:42:39