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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:14:36+00:00 2026-05-27T06:14:36+00:00

In Javascript, you can create an object with a property name this way: var

  • 0

In Javascript, you can create an object with a property name this way:

var person = { name: "Tucker" };

But also that way:

var person = { "name": "Tucker" };

Are these two equivalent? Which one is preferred?

Same goes with accessing a property:

person["name"] = "Dale";

vs.

person[name] = "Dale";

In Eloquent JavaScript, the author says that The part between the brackets can be any expression. It is converted to a string to determine the property name it refers to..

So, I guess directly putting a string between the brackets would be considered best practice.

Last but not least, properties can be accesses by using the dot notation:

person.name = "Dale";

if the property is a valid variable name. Does it actually makes sense to use this notation over the seemingly more flexible bracket notation?

  • 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-27T06:14:37+00:00Added an answer on May 27, 2026 at 6:14 am

    These are the same, the only difference is that if your key is reserved keyword, you need the quotes:

    var person = { name: "Tucker" };
    var person = { "name": "Tucker" };
    var person = { "for": "Tucker" }; //Need quotes here
    

    When accessing, the same rules apply

    person["name"] = "Dale"; //Sets the person object's name attribute to "Dale", the brackets are needed for variables or expressions.
    person.name = "Dale";    //Same operation, different syntax
    person[name] = "Dale";   //Sets the attribute equivalent to the value of the variable name, not necessarily "name"
    

    Does it actually makes sense to use this notation over the seemingly more flexible bracket notation?

    It is entirely up to you, or whoever decides your project’s coding standards. The dot notation is simpler and reminiscent of Java/C/C++ (if you’re into that sort of thing) and brackets, as you noted, are more flexible.

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

Sidebar

Related Questions

In javascript you can create a Date object from a string, like var mydate
I'm basically trying to create a generic object in javascript that I can use
In javascript you can easily create objects and Arrays like so: var aObject =
Im trying to find out a good JavaScript library that can create a nice
Can I create a javascript variable and increment that variable when I press a
I am looking to create a javascript widget that can be hosted on other
I like that in javascript, I can create a function, and then add further
With javascript, you can have one object inherit properties from another, so that if
I know we can create new properties in Javascript objects during runtime but could
Can I create an event so I can execute some javascript whenever an element

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.