# Prototypes — JavaScript

Source: https://www.geekswithgeeks.com/en/javascript/js-prototypes

> The mechanism classes are built on.

## The prototype chain

Every object has an internal link to a **prototype** object it falls back to for properties or methods it doesn't have directly.

## Prototype in action

`Object.create` builds an object whose prototype is explicitly set to another object.

```js
const animal = { eats: true };
const rabbit = Object.create(animal);
console.log(rabbit.eats);        // true, inherited
console.log(rabbit.hasOwnProperty("eats"));  // false
```

## A chain of fallbacks

Think of the prototype chain like asking a **parent, then grandparent** for something you don't have — JS keeps climbing until it finds the property or hits `null`.
