🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #216

Object Prototypes

Prototype Inheritance

All JavaScript objects inherit properties and methods from a prototype:

  • Date objects inherit from Date.prototype
  • Array objects inherit from Array.prototype

The Object.prototype is on the top of the prototype inheritance chain.

Date objects, Array objects, and all other objects inherit from Object.prototype.

Adding Properties and Methods to Objects

Sometimes you want to add new properties (or methods) to all existing objects of a given type.

Sometimes you want to add new properties (or methods) to an object constructor.

Previously you have learned learned how to use an object constructor:

Example

function Person(first, last, age, eyecolor) {

this.firstName = first;

  this.lastName = last;

this.age = age;

this.eyeColor = eyecolor;

}

const myFather = new Person("John", "Doe", 50, "blue");

const myMother = new Person("Sally", "Rally", 48, "green");

You cannot add a new property to an existing object constructor:

Example

Person.nationality = "English";

To add a new property to a constructor, you must add it to the constructor function:

Example

function Person(first, last, age, eyecolor) {

this.firstName = first;

this.lastName = last;

this.age = age;

this.eyeColor = eyecolor;
  this.nationality = "English";

}

Using the prototype Property

The JavaScript prototype property allows you to add new properties to object constructors:

Example

function Person(first, last, age, eyecolor) {

    this.firstName = first;

    this.lastName = last;

    this.age = age;

    this.eyeColor = eyecolor;

}

 Person.prototype.nationality = "English";

The JavaScript prototype property also allows you to add new methods to object constructors:

Example

function Person(first, last, age, eyecolor) {

    this.firstName = first;

    this.lastName = last;

    this.age = age;

  this.eyeColor = eyecolor;

}

 Person.prototype.name = function() {

    return this.firstName + " " + this.lastName;

};

Warning: Only modify your own prototypes. Never modify the prototypes of standard JavaScript objects.

Note: Advanced Chapters: JavaScript Object Definitions JavaScript Object Advanced this JavaScript Object Iterations JavaScript Object Getters & Setters JavaScript Object Management JavaScript Object Protection JavaScript Object Prototypes JavaScript Object Reference

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Object Prototypes – FAQs

Quick answers about learning Object Prototypes in JavaScript.

This free note from CodingNow 2.0 explains Object Prototypes in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including Object Prototypes, is 100% free with no signup required.
With focused practice, most students grasp Object Prototypes in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now