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 6234743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:32:31+00:00 2026-05-24T10:32:31+00:00

The in operator and hasOwnProperty methods appear to be interchangeable, but I’m wondering if

  • 0

The “in” operator and “hasOwnProperty” methods appear to be interchangeable, but I’m wondering if one is checking for inherited properties or something and the other isn’t or something like that. I’m especially interested in the case of using it with a Dictionary, but I doubt that is different from other uses.

“hasOwnProperty” is described in the official docs here and “in” is described here, but if there is a difference, I didn’t find it very clear.

  • 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-24T10:32:32+00:00Added an answer on May 24, 2026 at 10:32 am

    Trusting the preciously accepted answer actually got me into a little bit of trouble. There seems to be more going on than just prototype-related differences. What I’ve found is that

    hasOwnProperty cannot be used to see if a key is present in a Dictionary when that key is a reference type, but the in operator can.

    Here’s an example to demonstrate.

    code:

    var test:Function = function(key:*,label:String):void
        {
            var d:Dictionary = new Dictionary(true);
            d[key] = true;
            trace(label);
            trace("  hasOwnProperty: " + (d.hasOwnProperty(key)?"true":"false <== !!PROBLEM!!"));
            trace("  in: " + (key in d));
            trace("  []: " + d[key]);
        };
    test({}, "indexed by object");
    test("string", "key is string");
    test(0, "key is number");
    test(true, "key is boolean");
    

    results:

    indexed by object
      hasOwnProperty: false <== !!PROBLEM!!
      in: true
      []: true
    key is string
      hasOwnProperty: true
      in: true
      []: true
    key is number
      hasOwnProperty: true
      in: true
      []: true
    key is boolean
      hasOwnProperty: true
      in: true
      []: true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a thrush operator, I have a filter expression as one of the forms.
Possible Duplicate: Operator[][] overload I've looked on the internet but can't find a definitive
The conditional operator works in many attributes like rendered value and others. But it
Possible Duplicate: C++ Comma Operator that probably a trivial question, but I don't know
Mozilla's website clearly describes hasOwnProperty() and the in operator. However, it does not give
Java can't do operator overloading, but + works okay for String and Integer and
Why was the spaceship operator <=> chosen to have one equal sign rather than
Why is the assignment operator is not making a copy of the rvalue but
Possible Duplicate: Operator overloading Hi guys can some one please suggest a good tutorial
Vim % operator jumps to matching parentheses, comment ends and a few other things.

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.