Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612856
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:27:44+00:00 2026-05-22T01:27:44+00:00

I was playing around with instanceof in Chrome but I got an error message.

  • 0

I was playing around with instanceof in Chrome but I got an error message. I think I know why (you have to supply a function after the instanceof keyword that is the constructor the object was created with), but the error message seems to be stating something else:

[1,2,3] instanceof Array
// true

[1,2,3] instanceof []
// TypeError: Expecting a function in instanceof check, but got 1,2,3

Does this mean that I should replace [1,2,3] with a function? I would think that [1,2,3] is correct and that [] is the problem and should be replaced with a function, but it looks like the error message is saying the opposite.

Could someone please explain how I’m interpreting the error message incorrectly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:27:44+00:00Added an answer on May 22, 2026 at 1:27 am

    Objects are instances of a constructor function, so the test is to see if the left hand is an instance of the right, so the right must be a function (and it must be the constructor that constructed the object to return true).

    [1,2,3] instanceof [].constructor;  // true
    

    So to answer the question more directly, your initial understanding is correct, and the error message seems misleading (to me anyway).

    From the spec: http://ecma262-5.com/ELS5_HTML.htm#Section_11.8.6

    1.8.6 The instanceof operator

    The production RelationalExpression: RelationalExpression instanceof ShiftExpression is evaluated as follows:

    • Let lref be the result of evaluating RelationalExpression.
    • Let lval be GetValue(lref).
    • Let rref be the result of evaluating ShiftExpression.
    • Let rval be GetValue(rref).
    • If Type(rval) is not Object, throw a TypeError exception.
    • If rval does not have a [[HasInstance]] internal method, throw a TypeError exception.
    • Return the result of calling the [[HasInstance]] internal method of rval with argument lval.

    and http://ecma262-5.com/ELS5_HTML.htm#Section_15.3.5

    15.3.5 Properties of Function Instances

    In addition to the required internal properties, every function instance has a [[Call]] internal property and in most cases use a different version of the [[Get]] internal property. Depending on how they are created (see 8.6.2 ,13.2, 15, and 15.3.4.5), function instances may have a [[HasInstance]] internal property, a [[Scope]] internal property, a [[Construct]] internal property, a [[FormalParameters]] internal property, a [[Code]] internal property, a [[TargetFunction]] internal property, a [[BoundThis]] internal property, and a [[BoundArgs]] internal property.

    So it requires a TypeError if the right hand does not have an internal [[HasInstance]] property, but doesn’t specify the wording.

    Firefox 4 gives me a much more sensible error message:

    [1,2,3] instanceof [];
    
    // TypeError: invalid 'instanceof' operand []
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into
I've been playing around with Bouncy Castle's implementation of RSA (Lightweight API) and got
I have been looking around for an answer to my question but couldn't find
I have been playing around with modifiers with static method and came across a
I'm playing around with drawing in iOS apps. I have a class that is
I've been playing around a bit with the Tornado web server and have come
I have been playing around with Apple's sample code - UserDefaults - http://developer.apple.com/library/mac/#samplecode/UserDefaults/Introduction/Intro.html -
I have recently been playing around with Codeigniter to see what I can learn
I'm playing around with MySQL running in Ubuntu. I have sample data in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.