DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • Scope & Closures
  • Asynchronous JavaScript
  • DOM Manipulation
  • ES6+ to 2026
  • Execution Context & Call Stack
  • Hoisting: var, let, const & Functions
  • Data Types & Type Coercion
  • Prototypes & the this Keyword
  • The Event Loop Deep Dive
  • Higher-Order Functions, Currying & Functional Patterns
  • Callbacks, Promises & Async/Await
  • Event Delegation & DOM Optimization
  • Destructuring, Spread/Rest & Modern Syntax
  • ES Modules & the Fetch API
  • Memory Management & Garbage Collection
  • Debouncing, Throttling & Performance Patterns
  • Design Patterns in JavaScript
  • Proxies, Reflect & Symbols
  • JavaScript Optimizations & Best Practices
  • JavaScript Interview Questions (30 MCQs)
← From Beginner to Expert in Fundamentals of Frontend

Prototypes & the this Keyword

22 min read
Prototype Chain__proto__ vs prototypethis Keywordcall apply bindArrow FunctionsClassesPrivate Fields

Prototypal Inheritance

JavaScript doesn't use classical inheritance. Instead, objects delegate to other objects via the prototype chain.

The Prototype Chain

const animal = { speak() { return "..."; } };
const dog = Object.create(animal);
dog.bark = function() { return "Woof!"; };

dog.bark();  // "Woof!" (own property)
dog.speak(); // "..." (delegated to animal via prototype)
dog.toString(); // "[object Object]" (delegated to Object.prototype)

__proto__ vs prototype

PropertyExists OnPurpose
__proto__Every objectPoints to the object's prototype (the parent)
prototypeFunctions onlyThe object that will become __proto__ for instances
function Person(name) { this.name = name; }
Person.prototype.greet = function() { return `Hi, I'm ${this.name}`; };

const alice = new Person("Alice");
alice.__proto__ === Person.prototype; // true
Person.prototype.__proto__ === Object.prototype; // true
Object.prototype.__proto__ === null; // END of chain

The this Keyword

this is determined by HOW a function is called, not where it's defined.

Call Stylethis Value
func()window (or undefined in strict mode)
obj.func()obj
new Func()New empty object
func.call(ctx)ctx
func.bind(ctx)()ctx (permanently)
() => {}Lexical (inherits from parent scope)

Arrow Functions & this

const obj = {
  name: "Alice",
  // ❌ Arrow function inherits `this` from outer scope (window/module)
  greetArrow: () => console.log(this.name),
  // ✅ Regular function gets `this` = obj
  greetRegular() { console.log(this.name); }
};

obj.greetArrow();   // undefined
obj.greetRegular(); // "Alice"

call, apply, bind

function introduce(greeting) {
  return `${greeting}, I'm ${this.name}`;
}
const user = { name: "Bob" };

introduce.call(user, "Hello");    // "Hello, I'm Bob"
introduce.apply(user, ["Hello"]); // "Hello, I'm Bob"
const bound = introduce.bind(user);
bound("Hey");                      // "Hey, I'm Bob"

Classes (Syntactic Sugar)

class Animal {
  #sound; // Private field
  constructor(name, sound) {
    this.name = name;
    this.#sound = sound;
  }
  speak() { return `${this.name} says ${this.#sound}`; }
  static create(name, sound) { return new Animal(name, sound); }
}

class Dog extends Animal {
  constructor(name) { super(name, "Woof"); }
  fetch(item) { return `${this.name} fetches ${item}`; }
}

const rex = Dog.create("Rex", "Woof"); // Error: creates Animal, not Dog
const rex2 = new Dog("Rex");
rex2.speak(); // "Rex says Woof"

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.