Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Adding a new Property

This example demonstrates how to add a new property to an object.

Example

// Create an Object:
const person = {
  firstName: “John”,
  lastName : “Doe”,
  language : “EN”
};

// Add a Property
Object.defineProperty(person, “year”{value:“2008”});

Changing a Property Value

This example updates the value of a property.

Example

// Create an Object:
const person = {
  firstName: “John”,
  lastName : “Doe”,
  language : “EN”
};

// Change a Property
Object.defineProperty(person, “language”{value : “NO”});