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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:26:35+00:00 2026-05-24T08:26:35+00:00

From Javascript: The Definitive Guide, var o = { x:1 }; // Start with

  • 0

From Javascript: The Definitive Guide,

var o = { x:1 }; // Start with an object
o.x = 2; // Mutate it by changing the value of a property
o.y = 3; // Mutate it again by adding a new property

What does { x: 1} do here? With the braces, it reminds me of function (or for objects, constructor). Can someone please elaborate on it, thanks.

An additional related question is:

({x:1, y:2}).toString() // => "[object Object]"

I find this question interesting as well.
What is the difference between object and Object in the above code? In fact, when do we use Object?

  • 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-24T08:26:35+00:00Added an answer on May 24, 2026 at 8:26 am

    It makes the variable o into an object containing one property (x), and sets the value of that property to 1.

    Edit

    To be clear, as you demonstrated, you don’t have to add properties this way. You can create a property on an object simply by assigning it (o.y = "Awesomesauce")

    As to your related question; {x:1, y:2} is simply an object literal with two properties x and y with the values 1 and 2, respectively. operating on this object literal is just like operating on a primitive value literal (console.log("my,string".split(","))).

    "[object Object]" is just how a non-specifically typed object is represented in string form.

    Edit 2

    As per your comment: the lowercase "object" is the type. typeof o will give object. The Object (capital "O") is just a string representation of {x:1}. A string representation of an array or number is "smart" because it knows more specifically the type. With a custom object, like o, it’s just a generic object and thus writes: object (the type) Object (a string representation of o itself)

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

Sidebar

Related Questions

Some Context From Javascript: The Definitive Guide : When regexp is a global regular
Currently, I am using Javascript - The Definitive Guide for learning Javascript from scratch.
From the Flattr Javascript API description : <script type=text/javascript> <!--//--><![CDATA[//><!-- (function() { var s
Javascript - The Definitive Guide (6ed) shows the following code: Originally we have this
In the book JavaScript the definitive guide 5 edition , section 9.2 Prototypes and
From another answer on Stackoverflow is a conversion from Javascript date to .net DateTime:
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need to pass an array from JavaScript to a page method in C#.
How can I change CSS from javascript . I'm using jQuery-ui Dialog and I
I wish to load some additional data from javascript in an HTML page. 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.