Get to know MDN better
Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.
O operador instanceof testa se um objeto tem, em seu prototype, a função construtora.
O objeto a ser testado
construtorFunção construtora a ser verificada
O operador instanceof testa a presença da função construtora no prototype do objeto.
Note que o resultado do instanceof pode alterar quando a gente altera o prototype da função construtora. No entanto, a gente não pode alterar (por padrão) o prototype do objeto. Só é possível fazer essa alteração usando a pseudopropriedade __proto__.
Different scope have different execution environments. This means that they have different built-ins (different global object, different constructors, etc.). This may result in unexpected results. For instance, [] instanceof window.frames[0].Array will return false, because Array.prototype !== window.frames[0].Array and arrays inherit from the former. This may not make sense at first but when you start dealing with multiple frames or windows in your script and pass objects from one context to another via functions, this will be a valid and strong issue. For instance, you can securely check if a given object is in fact an Array using Array.isArray(myObj)
Nota: Note for Mozilla developers: In code using XPCOM instanceof has special effect: obj instanceof xpcomInterface (e.g. Components.interfaces.nsIFile) calls obj.QueryInterface(xpcomInterface) and returns true if QueryInterface succeeded. A side effect of such call is that you can use xpcomInterface's properties on obj after a successful instanceof test. Unlike standard JavaScript globals, the test obj instanceof xpcomInterfaceworks as expected even if obj is from a different scope.
The following code uses instanceof to demonstrate that String and Date objects are also of type Object (they are derived from Object).
However, objects created with the object literal notation are an exception here: Although the prototype is undefined, instanceof Object returns true.
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.
| ECMAScript® 2027 Language Specification # sec-relational-operators |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 12 de out. de 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.