Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Об'єкти | Section
Основи JavaScript

bookОб'єкти

Свайпніть щоб показати меню

Objects are a core feature in JavaScript that let you group related data and values together. An object is a collection of properties, where each property has a name (called a key) and a value.

This key-value structure makes objects ideal for representing real-world entities and organizing information in a flexible way. You define an object using curly braces {} and each property is written as a pair: the key (as a string or identifier), followed by a colon, and then the value. Multiple properties are separated by commas.

12345678
// Creating an object to represent a user profile const userProfile = { username: "coder123", age: 28, email: "coder123@example.com", isActive: true }; console.log(JSON.stringify(userProfile));
copy

You can access the properties of an object using either dot notation or bracket notation. For instance, userProfile.username gives you the value "coder123".

12345678910111213
const userProfile = { username: "coder123", age: 28, email: "coder123@example.com", isActive: true }; console.log(JSON.stringify(userProfile)); // Accessing object properties using dot notation console.log(userProfile.username); // Dot notation // Accessing object properties using bracket notation console.log(userProfile["email"]); // Bracket notation
copy

To update a property, you simply assign a new value: userProfile.age = 29;. If you want to add a new property, just assign it: userProfile.location = "New York";.

123456789101112131415
const userProfile = { username: "coder123", age: 28, email: "coder123@example.com", isActive: true }; console.log(JSON.stringify(userProfile)); // Update the existing 'age' property userProfile.age = 29; // Add a new 'location' property userProfile.location = "New York"; console.log(JSON.stringify(userProfile));
copy

Objects let you organize related data under a single variable, making your code more readable and easier to maintain.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 15

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 15
some-alt