Object initializer - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

Object literal syntax vs. JSON

The object literal syntax is not the same as the JavaScript Object Notation (JSON). Although they look similar, there are differences between them:

Object literal syntax vs. JSON

The object literal syntax is not the same as the JavaScript Object Notation (JSON). Although they look similar, there are differences between them:

property accessors

Once you have created an object, you might want to read or change them. Object properties can be accessed by using the dot notation or the bracket notation. (See property accessors for detailed information.)

Property definitions

We have already learned how to notate properties using the initializer syntax. Oftentimes, there are variables in your code that you would like to put into an object. You will see code like this:

Property definitions

We have already learned how to notate properties using the initializer syntax. Oftentimes, there are variables in your code that you would like to put into an object. You will see code like this:

Property definitions

We have already learned how to notate properties using the initializer syntax. Oftentimes, there are variables in your code that you would like to put into an object. You will see code like this:

Method definitions

A property of an object can also refer to a function or a getter or setter method.

Method definitions

A property of an object can also refer to a function or a getter or setter method.

Method definitions

A property of an object can also refer to a function or a getter or setter method.

method definitions

A property of an object can also refer to a function or a getter or setter method.

Object.prototype.__proto__

A property definition of the form __proto__: value or "__proto__": value does not create a property with the name __proto__. Instead, if the provided value is an object or null, it points the [[Prototype]] of the created

Learn how to contribute

This page was last modified on Jul 8, 2025 by MDN contributors.

Expressions and operators

Numbers and strings

Representing dates & times

Regular expressions