0Pricing
JavaScript Academy · Lesson

Prototype Chain & Own-Property Basics

Prototype chain basics; check own vs inherited properties; use Object.create; set simple descriptors.

Prototype Chain & Own-Property Basics is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 2. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 2 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro to prototypes

Goal: See how objects inherit through the prototype chain and how to tell own vs inherited keys.

  • Prototype chain
  • hasOwn vs in
  • Object.create
  • Basic descriptors
Prototype Chain & Own-Property Basics — illustration 1

Prototype lookup

If a key is not found on the object, JavaScript looks at its prototype (e.g., Object.prototype).

// A simple object
const user = { name: "Ayla" };

// The prototype is another object used for fallback lookups
const proto = Object.getPrototypeOf(user);

console.log("name:", user.name);
console.log("has toString?", typeof user.toString === "function");
console.log("proto same as Object.prototype?", proto === Object.prototype);
Prototype Chain & Own-Property Basics — illustration 2

Own vs inherited

Object.hasOwn(obj, key) returns true only for own keys. "key" in obj includes inherited ones.

// Own vs inherited checks
const point = { x: 1 };

// "in" sees own or inherited
console.log("x in point:", "x" in point);
console.log("toString in point:", "toString" in point);

// Only own keys
console.log("hasOwn x:", Object.hasOwn(point, "x"));
console.log("hasOwn toString:", Object.hasOwn(point, "toString"));
Prototype Chain & Own-Property Basics — illustration 3

Object.create basics

Object.create(proto) makes an object that inherits from proto.

// Use Object.create to set a prototype
const animal = { kind: "animal" };

// pet inherits from animal
const pet = Object.create(animal);
pet.name = "Milo";

console.log("pet name:", pet.name);
console.log("pet kind (inherited):", pet.kind);
console.log("hasOwn kind?", Object.hasOwn(pet, "kind"));
Prototype Chain & Own-Property Basics — illustration 4

Descriptors (light)

Object.defineProperty can set flags like writable and enumerable for a key.

// Define simple descriptors
const prefs = {};
Object.defineProperty(prefs, "theme", {
  value: "dark",
  writable: false,
  enumerable: true
});

// Try to change (silently fails in non-strict)
prefs.theme = "light";

console.log("theme:", prefs.theme);

// List keys: theme is enumerable
console.log("keys:", Object.keys(prefs));
Prototype Chain & Own-Property Basics — illustration 5

Tips & checklist

Tips:

  • Use Object.hasOwn(obj, key) to test own keys.
  • Prefer Object.create(proto) to make tiny prototypes.
  • Keep descriptor usage minimal at first; defaults are fine.
Prototype Chain & Own-Property Basics — illustration 6

Own vs inherited quiz

Quick check: Own property test.

Prototype Chain & Own-Property Basics — illustration 7

Recap

Recap: The engine looks up missing keys on the prototype. Use hasOwn for own keys only, Object.create to set a prototype, and descriptors to control basic flags.

Prototype Chain & Own-Property Basics — illustration 8

Frequently asked questions

Is the “Prototype Chain & Own-Property Basics” lesson free?

Yes — the full text of “Prototype Chain & Own-Property Basics” is free to read here on the web, and the JavaScript Academy course includes 2 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Prototype Chain & Own-Property Basics”?

Prototype chain basics; check own vs inherited properties; use Object.create; set simple descriptors. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 2, so you can start here or from the beginning and move at your own pace.

How long does the “Prototype Chain & Own-Property Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Prototype Chain & Own-Property Basics
  2. Class Syntax (Preview): constructor, methods, static, extends
← Back to JavaScript Academy