🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Working_with_objects
Working with objects - JavaScript | MDN
August 21, 2026 - JavaScript is designed on an object-based paradigm. An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method.
🌐
W3Schools
w3schools.com › js › js_objects.asp
JavaScript Objects
Getters and setters allow you to define Object Accessors (Computed Properties). ... Coding fundamentals as a game. Bite-sized lessons and challenges. ... Ready to start your journey? Your streak is waiting. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Object_basics
JavaScript object basics - Learn web development | MDN
3 weeks ago - Well, an object is made up of multiple members, each of which has a name (e.g., name and age above), and a value (e.g., ['Bob', 'Smith'] and 32). Each name/value pair must be separated by a comma, and the name and value in each case are separated by a colon. The syntax always follows this pattern:
🌐
Codecademy
codecademy.com › learn › game-dev-learn-javascript-objects › modules › game-dev-learn-javascript-objects › cheatsheet
Learn JavaScript: Objects: Learn JavaScript: Objects Cheatsheet | Codecademy
It uses a pair of curly braces ({}) with property names on the left-hand side of an assignment to extract values from objects. The number of variables can be less than the total properties of an object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object
Object - JavaScript | MDN
The Object type represents one of JavaScript's data types. It is used to store various keyed collections and more complex entities. Objects can be created using the Object() constructor or the object initializer / literal syntax.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › objects-in-javascript
Objects in JavaScript - GeeksforGeeks
There are two primary ways to create an object in JavaScript: The object literal syntax allows you to define and initialize an object with curly braces {}, setting properties as key-value pairs.
Published: January 16, 2026
🌐
Tabnine
tabnine.com › home › objects in javascript explained
Objects in JavaScript explained - Tabnine
July 25, 2024 - The literal notation syntax includes the Object reference variable name (const myObject), an assignment operator, an opening curly bracket, a list of key: value pairs, and finally a closing curly bracket.
🌐
Medium
medium.com › @developerObsessed › mastering-objects-in-javascript-71511ff8e00e
Mastering Objects in JavaScript. A Comprehensive Guide to Understanding… | by The Obsessed Developer | Medium
July 21, 2023 - Every object in JavaScript has an associated prototype object from which it inherits properties. With the introduction of ES6, JavaScript also supports class syntax for creating objects.
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Objects
So we can easily test whether the property exists: let user = {}; alert( user.noSuchProperty === undefined ); // true means "no such property" There’s also a special operator "in" for that. The syntax is: "key" in object ·
🌐
Mimo
mimo.org › glossary › javascript › object
JavaScript Object: Syntax, Usage, and Examples
Each item in an object is stored as a key-value pair, making it ideal for representing structured data. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › js › js_object_definition.asp.html
JavaScript Objects
Strings can be objects (or primitive data treated as objects) ... In JavaScript, all values, except primitive values, are objects.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › object in javascript
Object in JavaScript: Methods & Characteristics with Examples
December 20, 2023 - An object in JavaScript is a variable that contains a different value. It acts as a storage space for a set of values. Objects are one of the most important data types in JavaScript. The object contains properties, types and it’s a separate entity. It is a non-primitive datatype.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Top answer
1 of 8
186

There is no best way, it depends on your use case.

  • Use way 1 if you want to create several similar objects. In your example, Person (you should start the name with a capital letter) is called the constructor function. This is similar to classes in other OO languages.
  • Use way 2 if you only need one object of a kind (like a singleton). If you want this object to inherit from another one, then you have to use a constructor function though.
  • Use way 3 if you want to initialize properties of the object depending on other properties of it or if you have dynamic property names.

Update: As requested examples for the third way.

Dependent properties:

The following does not work as this does not refer to book. There is no way to initialize a property with values of other properties in a object literal:

var book = {
    price: somePrice * discount,
    pages: 500,
    pricePerPage: this.price / this.pages
};

instead, you could do:

var book = {
    price: somePrice * discount,
    pages: 500
};
book.pricePerPage = book.price / book.pages;
// or book['pricePerPage'] = book.price / book.pages;

Dynamic property names:

If the property name is stored in some variable or created through some expression, then you have to use bracket notation:

var name = 'propertyName';

// the property will be `name`, not `propertyName`
var obj = {
    name: 42
}; 

// same here
obj.name = 42;

// this works, it will set `propertyName`
obj[name] = 42;
2 of 8
118

There is various way to define a function. It is totally based upon your requirement. Below are the few styles :-

  1. Object Constructor
  2. Literal constructor
  3. Function Based
  4. Protoype Based
  5. Function and Prototype Based
  6. Singleton Based

Examples:

  1. Object constructor
var person = new Object();

person.name = "Anand",
person.getName = function(){
  return this.name ; 
};
  1. Literal constructor
var person = { 
  name : "Anand",
  getName : function (){
   return this.name
  } 
} 
  1. function Constructor
function Person(name){
  this.name = name
  this.getName = function(){
    return this.name
  } 
} 
  1. Prototype
function Person(){};

Person.prototype.name = "Anand";
  1. Function/Prototype combination
function Person(name){
  this.name = name;
} 
Person.prototype.getName = function(){
  return this.name
} 
  1. Singleton
var person = new function(){
  this.name = "Anand"
} 

You can try it on console, if you have any confusion.

🌐
DEV Community
dev.to › wisdomudo › javascript-object-literals-explained-syntax-examples-and-best-practices-1g8a
JavaScript Object Literals Explained: Syntax, Examples, and Best Practices - DEV Community
August 26, 2025 - Object literals are a widely used and efficient method for creating structured data in JavaScript. They let you represent real-world entities (users, settings, API responses) as key-value collections using a compact { ... } notation.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › create
Object.create() - JavaScript | MDN
With Object.create(), we can create an object with null as prototype. The equivalent syntax in object initializers would be the __proto__ key.
🌐
BrainStation®
brainstation.io › learn › javascript › object
JavaScript Object (2026 Tutorial & Examples) | BrainStation®
February 4, 2025 - When using dot notation to access property values from an object, you specify the name of the object followed by the dot and followed by the key that you are interested in accessing the value for.
🌐
CodeHints
codehints.io › javascript › objects
Objects in JavaScript | CodeHints
The Object constructor is another way to create an object. This is a more explicit approach, and it can be used when you want to create an empty object, and then add properties to it. The blueprint for the object must be outlined first - this can be done be using object-oriented programming in JavaScript.
🌐
Medium
medium.com › @mandeepkaur1 › creating-objects-in-javascript-a896e6cfa6eb
Creating Objects in JavaScript. JavaScript is an object-based language… | by Mandeep Kaur | Medium
October 16, 2020 - For example, the getName() method below takes two properties of the userProfile001 object (firstName and lastName) and returns the user’s full name. The this keyword refers to the current object of which properties the method is calling. ... The second method of creating a JavaScript object is to use the constructor function.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › objects.html
TypeScript: Documentation - Object Types
In JavaScript, the fundamental way that we group and pass around data is through objects. In TypeScript, we represent those through object types. ... In all three examples above, we’ve written functions that take objects that contain the property name (which must be a string) and age (which must be a number). We have cheat-sheets available for both type and interface, if you want a quick look at the important every-day syntax at a glance.