objectname.constructor==Object vs typeof objectname === “object”

Please see the comments on the last two lines of code. What does constructor==Object do?
To check whether something is an object I found out that we use this:

typeof instance === “object”

So what exactly does constructor==Object do or what are we doing it instead of doing typeof instance === “object”?

  **Your code so far**

function Dog(name) {
this.name = name;

// Only change code below this line
Dog.prototype = {
//constructor: Dog,
numLegs: 4,
eat: function() {
  console.log("nom nom nom");
describe: function() {
  console.log("My name is " + this.name);
let woof=new Dog();
console.log(woof.constructor===Object); //what does this do?
console.log(typeof woof==="object"); //isn't this how we check whether something is an object or not

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.177

Challenge: Remember to Set the Constructor Property when Changing the Prototype

Link to the challenge:

woof is an object returned by new Dog().

woof.constructor looks for a "constructor" property along woof's prototype chain, which does exist and has the global Object function as it’s value, as is the case for all objects.

=== Object compares the left side of === to the global function Object.

typeof operator return a string indicating the type of its operand.

woof is an object so typeof woof will return "object".

=== "object" compares the left side of === to the string "object"

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.