DEV Community

Cover image for Understanding __proto__ in JavaScript
Suvankarr Dash
Suvankarr Dash

Posted on

Understanding __proto__ in JavaScript

proto is a legacy JavaScript accessor that exposes an object’s internal prototype reference ([[Prototype]]). This prototype link defines where JavaScript looks next when a property is not found directly on an object.

Although obj.proto is widely supported, changing it at runtime is not recommended. Modifying the prototype chain dynamically can degrade performance and interfere with JavaScript engine optimizations.

Modern JavaScript provides safer, standard alternatives:

  • Object.getPrototypeOf(obj) to read an object’s prototype
  • Object.create(proto) to create objects with a specific prototype
  • Object.setPrototypeOf(obj, proto) (use sparingly)

Ex: -
const proto = { greet() { return 'hi'; } };
const obj = Object.create(proto);

Object.getPrototypeOf(obj) === proto; // true

Best practice: avoid using proto directly—treat it as a debugging aid, not a design tool.

Top comments (0)