0

I'm trying to understand better OOP. Anyone can explain what is the difference between this two object below? How javascript can display the both are varible of type object, if both seems completely different.

class Dog {
  constructor(name) {
    this.name = name;
  }

  bark() {
    console.log(`Woof! My name is ${this.name}`);
  }
}

const fido = new Dog('Fido');
fido.bark(); 

console.log(typeof fido)

let dog = { name : "Baby"};
console.log(typeof dog)
gu.gil
  • 1
  • 1
  • Well, they are both objects, even if different. Instead of using `typeof `try using `instanceof Dog` – Krzysztof Krzeszewski Jan 08 '23 at 15:17
  • Does this answer your question? [What is the difference between typeof and instanceof and when should one be used vs. the other?](https://stackoverflow.com/questions/899574/what-is-the-difference-between-typeof-and-instanceof-and-when-should-one-be-used) – Aleksandar Jan 08 '23 at 15:23
  • @Aleksandar and how should that answer `How javascript can display the both are varible of type object`? Both would still be an instance of Object, so the question would be essentially the same? – t.niese Jan 08 '23 at 15:43

0 Answers0