bhylu.com

Advertisements

Object Prototypes

An object can inherit from another object. A property lookup checks the object first, then follows its prototype chain.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const defaults = {currency: "GBP"};
const session = Object.create(defaults);
session.price = 6;
console.log(session.currency, Object.hasOwn(session, "currency"));

What happens

The currency is inherited, so the own-property check is false.