JavaScript Objects Worksheet

Question 1

What makes up an object (what does an object consist of)?

An object in JavaScript is a way to group related information together. Think of it like a "thing" with characteristics and actions.
Characteristics (Properties): An object has properties that describe it. Each property has a name and a value.
Actions (Methods):
An object can also have actions it can perform, called methods.
Methods are just functions (or bits of code that do something) stored inside an object.
Objects Inside Objects:
You can have objects inside objects, which is helpful when you want to add more details.

Question 2

What are two different types of notations that you can use when working with the properites of objects? For example, there are two types of syntax that you could use if you wanted to update a property of an object.

Dot Notation: This is the easiest and most common way. Just type the object name, add a dot, and then the property name.

let car = { make: "Toyota" }; car.make = "Honda";
Bracket Notation:
This way uses square brackets around the property name, like object["property"].
You’ll usually use this if the property name has spaces, special characters, or if you want to use a variable to access it.
let car = { make: "Toyota" };
car["make"] = "Honda"; // Changes 'make' to "Honda"

Question 3

Why are objects an important data type in JavaScript?

Objects are really important in JavaScript because they help you store and organize data in one place. Here’s why they matter:
Keep Related Stuff Together:
Instead of making a bunch of separate variables, you can put everything related to one thing in an object.
So, if you have a car, you don’t need separate make, model, and year variables—you can just keep it all in one car object:
Hold Different Types of Data:
Objects are flexible and can hold numbers, strings, arrays, other objects, and even functions. So, you can put all sorts of data together in one object.
JavaScript Uses Objects a Lot:
JavaScript relies on objects everywhere. Things like arrays, functions, and even parts of a webpage can be objects. So, knowing objects is key to using JavaScript well.

Question 4

When creating an object, what character is used to separate property names from their values?

When creating an object in JavaScript, a colon (:) is used to separate property names from their values.

Question 5

When creating an object, what character is used to separate the property/value pairs in an object?

When creating an object in JavaScript, a comma (,) is used to separate the property/value pairs.

Question 6

What operator is used to access a property of an object?

The dot operator (.) is used to access a property of an object.

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.