HasOwnProperty goal


#1

Does someone can explain what's the goal of this code ?

var hasOwn = Object.prototype.hasOwnProperty("hasOwnProperty");
console.log(hasOwn);

It looks like it can be only useful in this case. I feel confused about it...

Thanks my codemates! :relaxed:


#2

That will check if the Object() object has the "hasOwnProperty" method using itself.


#3

@ijulian28, from MDN - Object.prototype.hasOwnProperty()

The hasOwnProperty() method returns a boolean indicating whether the object has the specified property.

Description:

Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object;

In console you can check that Object() has property hasOwnProperty:

That's why

console.log(hasOwn); // true.


#4

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