0

Why does,

console.log(Object.getPrototypeOf({}));

logs {} to the terminal and

console.log(Object.getPrototypeOf({}) === Object.prototype);

logs true to the terminal?

Shouldn't the output on the former be Object.prototype?

CRice
  • 29,968
  • 4
  • 57
  • 70
Saif Al Falah
  • 358
  • 5
  • 16
  • 1
    Did you out put `console.log(Object.prototype)`? It's the same as `console.log(Object.getPrototypeOf({}))`... that's why the `true` – lealceldeiro Jul 09 '18 at 20:07
  • 1
    `Object.prototype` is a value, more specifically an object, so it prints like an object. It's like when you define your own object property (let's say you have defined `myObj = {id: 1}`). When you print `myObj.id` you wont see `myObj.id`, but 1. – trincot Jul 09 '18 at 20:09
  • 1
    The `console` API does whatever it wants to do. You should not rely on it being a useful aid when you're doing language semantics research. – Pointy Jul 09 '18 at 20:09
  • `Object.prototype` is a value, ok. So how do I view methods on the `Object.prototype`? Like `toString()`? – Saif Al Falah Jul 09 '18 at 20:11
  • Possible duplicate of [Object.getPrototypeOf() confusion](https://stackoverflow.com/questions/10013544/object-getprototypeof-confusion) – Heretic Monkey Jul 09 '18 at 20:11

0 Answers0