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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:49:56+00:00 2026-05-29T23:49:56+00:00

If I declare an object as follows: var foo.bar = new Object; Does that

  • 0

If I declare an object as follows:

var foo.bar = new Object;

Does that automatically make foo an object? If not and I want both foo and foo.bar to be objects do I need to use the following code:

var foo = new Object;
var foo.bar = new Object;

And if I create these two objects as above, is there a parent/child relationship between them or are they completely separate entities?

I apologize for the simple nature of my question, but I am trying to more fully understand the various ways data can be structured.

  • 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-29T23:49:57+00:00Added an answer on May 29, 2026 at 11:49 pm

    If I declare an object as follows:

      var foo.bar = new Object;
    

    Does that automatically make foo an object?

    No. It’s a syntax error;

    SyntaxError: Unexpected token .

    If not and I want both foo and foo.bar to be objects do I need to use the following code:

    var foo = new Object;
    var foo.bar = new Object;
    

    No, that’s again a syntax error. You should be using.

    var foo = new Object;
    foo.bar = new Object;
    

    But it’s more common to use object literal syntax these days;

    var foo = {
        bar: {
    
        }
    }
    

    And if I create these two objects as above, is there a parent/child relationship between them or are they completely separate entities?

    They are completely separate entities. The only link between them is that foo holds a reference to bar. Something else can easily hold a reference to bar;

    var baz = foo.bar;
    // Now baz and foo.bar are both pointing to the same object
    
    alert(baz === foo.bar); // true;
    baz.attr = 1;
    alert(baz.attr); // 1
    alert(foo.bar.attr); // 1
    
    delete foo.bar; // delete foo's reference to bar
    alert(baz.attr); // still shows 1
    alert(foo.bar.attr); // error, because we deleted `bar`.
    

    Try it yourself… http://jsfiddle.net/AMXLE/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code an array is declared as follows private Object[,] cellInfos = new
It's known that you should declare events that take as parameters (object sender, EventArgs
I have objects with many variables that I declare and explain in the comments.
If I declare just the 2 varargs methods as follows: public void foo(String... strings)
Background Currently, if I want to create a new object in C# or Java,
Is there anyway to declare an object of a class before the class is
How to declare a static dictionary object inside a static class? I tried public
Consider an object declared in a method: public void foo() { final Object obj
I see this all the time: object literals declared such that some keys are
I want to pull a tree structured set of objects from a web service

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.