JS: Object.getPrototypeOf 👎

By Xah Lee. Date: . Last updated: .

Object.getPrototypeOf

Object.getPrototypeOf(obj)

Return the parent of object obj.

🛑 warning: if obj is not an object, it is converted to object first.

🟢 tip: better is Reflect.getPrototypeOf.

console.assert(
 Object.getPrototypeOf({}) === Object.prototype,
);

Edge case. when arg is not an object

// when arg is not an object
console.log(
 Object.getPrototypeOf(3),
);
// {}