🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Object_basics
JavaScript object basics - Learn web development | MDN
An object like this is referred to as an object literal — we've literally written out the object contents as we've come to create it.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Literal
Literal - Glossary - MDN Web Docs
July 11, 2025 - A string literal is zero or more ... or both double quotation marks). ... An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({})....
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Working_with_objects
Working with objects - JavaScript - MDN Web Docs - Mozilla
February 21, 2026 - The syntax for an object using an object initializer is: ... const obj = { property1: value1, // property name may be an identifier 2: value2, // or a number "property n": value3, // or a string }; Each property name before the colon is either an identifier, a number literal, or a string literal, and each valueN is an expression whose value is assigned to the property name.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object
Object - JavaScript - MDN Web Docs
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.
🌐
Amberwilson
amberwilson.co.uk › learn › object literals
Object Literals | Amber Wilson
Object literals are a data structure that can be used in JavaScript. I really like seeing how data can be organised and object literals do this really nice and tidily. Here's an example: var cat = { myCat: 'Tabby', getCat: catTypes('Siamese'), ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Object
Object - Glossary - MDN Web Docs
July 11, 2025 - In JavaScript, objects can be seen as a collection of properties. With the object literal syntax, a limited set of properties are initialized; then properties can be added and removed. Property values can be values of any type, including other objects, which enables building complex data structures.
🌐
Reddit
reddit.com › r/learnjavascript › could you explain an object literal as simply as possible please?
Could you explain an object literal as simply as possible please? : r/learnjavascript
November 28, 2022 - Edit: u/senocular, can you please let me know whether I should retain null in that list. The MDN article on literals doesn't include it, but the article on null says the value null is written with a literal: null.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Grammar_and_types
Grammar and types - JavaScript - MDN Web Docs - Mozilla
The exponent part is an e or E ... either a decimal point or e (or E). ... An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({})....
Find elsewhere
🌐
Unibo
lia.disi.unibo.it › materiale › JS › developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Object_initializer.html
Object initializer - JavaScript | MDN
Objects can be initialized using new Object(), Object.create(), or using the literal notation (initializer notation). An object initializer is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}).
Top answer
1 of 8
228

Computed property names are supported in ECMAScript2015:

var name = 'key';
var value = 'value';
var o = {
  [name]: value
};
console.log("o as json : " + JSON.stringify(o));

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer

2 of 8
112

Prior to ECMAScript 2015 (ed 6), an object literal (ECMAScript calls it an "object initializer") key must be one of:

  1. IdentifierName
  2. StringLiteral
  3. NumericLiteral

So you couldn't use an expression as the key in an initialiser. This was changed as of ECMAScript 2015 (see below). You could use an expression with square bracket notation to access a property, so to set the properties with an expression you had to do:

var required = { directories : {}};
required.directories[this.applicationPath] = "Application " + this.application + " does not exists";
required.directories[this.applicationPath + "/configs"] = "Application config folder does not exists";
...

and so on. Since this.applicationPath is reused a lot, better to store a reference to help with performance and cut down the amount of code:

var a = this.applicationPath;
var required = { directories : {}};
var rd = required.directories;
rd[a] = "Application " + this.application + " does not exists";
rd[a + "/configs"] = "Application config folder does not exists";
...

Edit

As of ECMAScript 2015 (ed 6), object initializers can have computed keys using:

[expression]: value

There is also shorthand syntax for property and method names.

See MDN: Object Initializer or ECMAScript Object Initializer.

🌐
DEV Community
dev.to › og_dev › level-up-your-js-object-literal-enhancements-that-will-change-your-code-jbc
Level Up Your JS: Object Literal Enhancements That Will Change Your Code - DEV Community
October 8, 2024 - This feature is powerful when you need to create objects with dynamic keys based on some logic or external data. MDN Documentation: Computed property names · ES6 introduced a new way to define methods in object literals using the get and set keywords.
🌐
MDN
mdn2.netlify.app › en-us › docs › glossary › object
Object - MDN Web Docs Glossary: Definitions of Web-related terms | MDN
February 18, 2022 - With the object literal syntax, a limited set of properties are initialized; then properties can be added and removed. Property values can be values of any type, including other objects, which enables building complex data structures.
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › glossary › object › index.md
content/files/en-us/glossary/object/index.md at main · mdn/content
With the [object literal syntax](/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#object_literals), a limited set of properties are initialized; then properties can be added and removed.
Author   mdn
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › learn › javascript › objects › basics › index.md
content/files/en-us/learn/javascript/objects/basics/index.md at main · mdn/content
An object like this is referred to as an **object literal** — we've literally written out the object contents as we've come to create it.
Author   mdn
🌐
SitePoint
sitepoint.com › blog › es6 › es6 in action: enhanced object literals
ES6 in Action: Enhanced Object Literals — SitePoint
November 7, 2024 - There are many resources available online where you can learn more about ES6 Enhanced Object Literals. Some good places to start include the Mozilla Developer Network (MDN) and various JavaScript tutorials and blogs.
🌐
Google Translate
translate.google.com › translate
Literal - Glossário - MDN Web Docs
A string literal is zero or more ... or both double quotation marks). ... An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({})....
🌐
Unibo
lia.disi.unibo.it › materiale › JS › developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Working_with_Objects.html
Working with objects - JavaScript | MDN
Object initializers are expressions, and each object initializer results in a new object being created whenever the statement in which it appears is executed. Identical object initializers create distinct objects that will not compare to each other as equal. Objects are created as if a call to new Object() were made; that is, objects made from object literal expressions are instances of Object.