Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between instanceof and constructor property

Tags:

javascript

Is a instanceof b exactly equivalent to a.constructor === b? If not, what's the difference between the two?

like image 353
frogatto Avatar asked Aug 11 '13 14:08

frogatto


People also ask

What is the difference between Instanceof and Typeof?

typeof: Per the MDN docmentation, typeof is a unary operator that returns a string indicating the type of the unevaluated operand. instanceof: is a binary operator, accepting an object and a constructor. It returns a boolean indicating whether or not the object has the given constructor in its prototype chain.

What is Instanceof in angular?

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. Its behavior can be customized with Symbol.

What is Instanceof in JS?

The instanceof operator in JavaScript is used to check the type of an object at run time. It returns a boolean value if true then it indicates that the object is an instance of a particular class and if false then it is not.

How do I know if an object is an instance?

The java “instanceof” operator is used to test whether the object is an instance of the specified type (class or subclass or interface). It is also known as type comparison operator because it compares the instance with type. It returns either true or false.


1 Answers

No.

instanceof also checks for "inherited" constructors.

For more information, see the spec. (here and here)

like image 133
SLaks Avatar answered Sep 22 '22 19:09

SLaks