Why is Object.prototype instanceof Object false?

Asked
Active3 hr before
Viewed126 times

8 Answers

object
90%

The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor., GitLab launches Collective on Stack Overflow , Meta Stack Overflow , Stack Overflow Public questions & answers

Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.

Object.prototype

Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.

Object

Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.

.prototype
load more v
88%

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value. , The instanceof operator tests the presence of constructor.prototype in object's prototype chain. , Note that the value of an instanceof test can change based on changes to the prototype property of constructors. It can also be changed by changing an object's prototype using Object.setPrototypeOf. It is also possible using the non-standard __proto__ property. , The following code creates an object type Car and an instance of that object type, mycar. The instanceof operator demonstrates that the mycar object is of type Car and of type Object.

object instanceof constructor
load more v
72%

Java - The null instanceof object evaluates to true and false , javascript - Why? Object.prototype ===To myNewObj.prototype ? , javascript - Object.prototype Returns an empty object in node , javascript - Why does its instanceof constructor return false even if it is in the chain?

Why does the following return false?

Object.prototype instanceof Object
65%

Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.,The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.,a instanceof b is equivalent to b.prototype.isPrototypeOf(a) - it tests whether b.prototype is in the prototype chain of a. In your case, it is not in the chain, because it is the start of the chain itself. isPrototypeOf is not reflexive.

Why does the following return false?

Object.prototype instanceof Object
75%

Because it basically asks whether Object.prototype does inherit from Object's .prototype object: It does not.,This filtered array is then added to an object literal that also defines the other two properties courseType and courseName. That new object is what the course type is mapped to. courseTypes.map returns an array of those objects.,Here is the same code made compatible with older browsers (no arrow functions, no includes, which were introduced in ES2015):,It uses .filter to collect those matches. The filter callback uses includes to determine if there is a match -- it returns a boolean, exactly what the filter callback expects as return value.

Why does the following return false?

Object.prototype instanceof Object
load more v
40%

The instanceof operator allows to check whether an object belongs to a certain class. It also takes inheritance into account.,Normally, instanceof examines the prototype chain for the check. We can also set a custom logic in the static method Symbol.hasInstance.,The instanceof operator,We can use {}.toString.call instead of instanceof for built-in objects when we want to get the type as a string rather than just to check.

obj instanceof Class
load more v
22%

The instanceof operator tests the presence of constructor.prototype in object's prototype chain.,The instanceof tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value. ,To test if an object is not an instanceof a specific constructor, you can do,However, objects created with the object literal notation are an exception here: Although the prototype is undefined, instanceof Object returns true.

Syntax

object instanceof constructor
load more v
60%

delete affects only the direct (“own,” noninherited) properties of an object. Its prototypes are not touched (see Deleting an inherited property)., Inheriting prototype properties. ,Getters and setters are inherited from prototypes:, Some operations consider the whole prototype chain and see inherited properties.

JavaScript’s object literals allow you to directly create plain objects (direct instances of Object). The following code uses an object literal to assign an object to the variable jane. The object has the two properties: name and describe. describe is a method:

var jane = {
   name: 'Jane',

   describe: function() {
      return 'Person named ' + this.name; // (1)
   }, // (2)
};
load more v

Other "object-undefined" queries related to "Why is Object.prototype instanceof Object false?"