Search⌘ K
AI Features

Setting & Deleting Properties

Explore how to add, update, and remove properties from JavaScript objects using dot notation and square bracket syntax. Understand how the delete operator works to remove properties and functions from objects, and when it cannot delete variables or global functions.

Setting Values Using Dot Notation

A property being accessed by the dot operator can be set/updated using the assignment operator (=).

Example

Let’s take a look at an example to see the implementation.

Javascript (babel-node)
//creating an object named employee
var employee = {
//defining properties of the object
//setting data values
name : 'Joe',
age : 20
}
console.log("Originally age was:",employee.age)
//updating the value of "age"
employee.age = 24
console.log("New age is:",employee.age)

Adding Properties

What if the ...

Ask