Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Working with Properties | Objects Fundamentals
JavaScript Data Structures

Working with PropertiesWorking with Properties

Let's examine three important concepts related to working with object properties:

  • Modifying property values;
  • Adding new properties;
  • Using shorthand properties.

Modifying Property Values

After creating an object, you can easily change the values of its properties. To do this, we simply refer to the property by name, using dot notation, and assign a new value.

Let's consider an example with a company object:

In this example, we change the values of the industry and founded.year properties.

Adding New Properties

Adding a new property to an object is no different from changing the value of an existing property. If a property with a specified name doesn't already exist in the object, it will be created.

Consider the company object from the previous example:

In this example, we add the new property founder to the company object.

Using Shorthand Properties

Shorthand properties simplify the process of creating objects, especially when you want to use variable or function parameter values as property values.

This syntax allows us to use the variable name as the property name and its value as the property value.

Consider the following example:

Using shorthand properties, the same object can be created more succinctly:

With shorthand properties, we only need to specify the property name, and the value is automatically taken from a variable with the same name.

1. After creating an object, how can we change the values of its properties?
2. What happens when you attempt to modify the value of a property that doesn't exist in an object using dot notation?
3. Which of the following examples demonstrates using shorthand properties for object creation?
4. How can you include the variable `city` as a property of `userLocation` using shorthand properties?

After creating an object, how can we change the values of its properties?

Виберіть правильну відповідь

What happens when you attempt to modify the value of a property that doesn't exist in an object using dot notation?

Виберіть правильну відповідь

Which of the following examples demonstrates using shorthand properties for object creation?

Виберіть правильну відповідь

How can you include the variable city as a property of userLocation using shorthand properties?

Виберіть правильну відповідь

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

Секція 2. Розділ 7
course content

Зміст курсу

JavaScript Data Structures

Working with PropertiesWorking with Properties

Let's examine three important concepts related to working with object properties:

  • Modifying property values;
  • Adding new properties;
  • Using shorthand properties.

Modifying Property Values

After creating an object, you can easily change the values of its properties. To do this, we simply refer to the property by name, using dot notation, and assign a new value.

Let's consider an example with a company object:

In this example, we change the values of the industry and founded.year properties.

Adding New Properties

Adding a new property to an object is no different from changing the value of an existing property. If a property with a specified name doesn't already exist in the object, it will be created.

Consider the company object from the previous example:

In this example, we add the new property founder to the company object.

Using Shorthand Properties

Shorthand properties simplify the process of creating objects, especially when you want to use variable or function parameter values as property values.

This syntax allows us to use the variable name as the property name and its value as the property value.

Consider the following example:

Using shorthand properties, the same object can be created more succinctly:

With shorthand properties, we only need to specify the property name, and the value is automatically taken from a variable with the same name.

1. After creating an object, how can we change the values of its properties?
2. What happens when you attempt to modify the value of a property that doesn't exist in an object using dot notation?
3. Which of the following examples demonstrates using shorthand properties for object creation?
4. How can you include the variable `city` as a property of `userLocation` using shorthand properties?

After creating an object, how can we change the values of its properties?

Виберіть правильну відповідь

What happens when you attempt to modify the value of a property that doesn't exist in an object using dot notation?

Виберіть правильну відповідь

Which of the following examples demonstrates using shorthand properties for object creation?

Виберіть правильну відповідь

How can you include the variable city as a property of userLocation using shorthand properties?

Виберіть правильну відповідь

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

Секція 2. Розділ 7
some-alt