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

  • Home
  • SEARCH
  • 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 7857909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:11:31+00:00 2026-06-02T21:11:31+00:00

Please help me in understanding this piece of code. var person = { ‘first-name’:

  • 0

Please help me in understanding this piece of code.

var person = {
    'first-name': 'FirstName',
    'last-name': 'LastName',
    'gender': 'Male'
};

var anotherPerson = new Object(person);
anotherPerson.desig = 'Designation';

console.log('Another person designation: ' + anotherPerson['desig'] + ', person designation: ' + person['desig']);

I expected the output to be Another person designation: Designation, person designation: undefined but to my surprise I found it to be `Another person designation: Designation, person designation: Designation.

According to me anotherPerson is extending person object and properties set to anotherPerson should not be visible to person object. Am I wrong here? Or is that both the object are pointing to the same location?

[EDIT]

Now there are even more surprises.

I added the following code to the above.

person.place = 'XYZ';
console.log(person['place'] + ', ' + anotherPerson['place']); // Expected: XYZ, undefined. Result: XYZ, XYZ.

Based on the above result and answers I thought that both objects are referring to the same location. Now I added few more lines

person = undefined;
console.log(anotherPerson['place']) //Expected: error, Result: XYZ. ??!?!?
console.log(person['place']) // Expected: error, Result: error.

Can someone throw some light on me to understand this?
Thanks for your help in advance

  • 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-06-02T21:11:33+00:00Added an answer on June 2, 2026 at 9:11 pm

    You are not doing extending or any kind of inheritance.

    This comes closer:

    var Person = function () {
        this["first-name"] = 'FirstName',
        this["last-name"] = 'LastName',
        this["gender"] = 'Male'
    };
    
    var person = new Person();
    var anotherPerson = new Person();
    

    Now you have two seperate instances of Person. If you also want anotherPerson to be a subclass ..

    var Person = function () {
        this["first-name"] = 'FirstName',
        this["last-name"] = 'LastName',
        this["gender"] = 'Male'
    };
    
    var AnotherPerson = function () {
        this.desig = "Designation";
    }
    AnotherPerson.prototype = new Person();   // inherit from Person
    AnotherPerson.prototype.constructor = AnotherPerson;  // reset constructor
    
    var person = new Person();
    var anotherPerson = new AnotherPerson();
    
    console.log(person.desig); // undefined
    console.log(anotherPerson.desig); // Designation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me someone with this code. CSS Code #nav, #nav ul { width:1000px;
Please help with understanding php regular expressions. Have this string: <a href=/kop/product/acer-timeline-5810tg-944g50mi class=imagecache imagecache-product_list
i have written a small piece of code. This code first blocks the {SIGSEGV},
Please help me understanding this: When home button is pressed and iPhone application goes
Please help me in understanding the below code. The function get_digit takes a character
Please help me with my understanding. Also I am not talking about SSL or
Please help me with this issue in my script. At the point of the
Please help me to discover whether this is a bug in Python (2.6.5), in
could someone please help me out with the (simplified) code below. I'm trying to
Please help me understand what this typedef is doing?? typedef void (xyz) (void *data);

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.