Lesson 14 of 15
Objects
Objects
Objects store key-value pairs. Keys are strings (called properties), values can be anything:
const person = {
name: "Alice",
age: 30,
active: true,
};
Accessing Properties
Use dot notation or bracket notation:
console.log(person.name); // Alice
console.log(person["age"]); // 30
Modifying Objects
person.age = 31; // update
person.email = "a@b.com"; // add new property
Methods
Objects can have functions as properties — these are called methods:
const circle = {
radius: 5,
area: function() {
return Math.PI * this.radius * this.radius;
},
};
console.log(circle.area().toFixed(2)); // 78.54
Your Task
Write function fullName(person) that returns the person's full name by joining person.first and person.last with a space.
JavaScript loading...
Loading...
Click "Run" to execute your code.