Represent Everyday Things with Objects
What is an Object?
When we take a look at an item, we can come up with a few key characteristics that describe it. Take for instance, a dog. When we think of a dog, we might describe it using characteristics like its name, its body size, fur color, etc… While each individual characteristic doesn’t represent a dog, collectively we get a sense of what a dog is.
Now, let’s think about how we could represent a dog in code. We could write all the dog’s information in a string, but it would be hard to extract information afterward. We could even store all the information in an array, but then we would have to rely on the ordering to keep track of each characteristic. What if we wrote out the information like so:
let theBestDogEver = {name: 'Air Bud',bodySize: 'large',furColor: 'golden'};
Then our “characteristics” are stored as a collection of key-value pairs, like the key of name
is tied with the value 'Air Bud'
. What we have in the example above is a JavaScript object! Generally, these “characteristics” that are tracked with key-value pairs are known as properties. These properties don’t follow any set order, rather these properties all exist inside the dog object and we can easily retrieve and manipulate the values by the key.
As you start learning more about objects, you’ll see how you’ve actually interacted with objects before and expand the possibilities of your programs!
Author
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Objects
Use this article as a reference sheet for JavaScript objects. - Article
Wix Data Module
Managing data is quick and easy with database collections built right into the Editor. For even more customization, the wix-data module gives you greater functionality for manipulating, and querying data.
Learn more on Codecademy
- Free course
Create a Professional Website with Velo by Wix
From beginners to experienced web developers, Wix offers a wide range of solutions to quickly create a website that you can proudly share.Beginner Friendly17 hours - Free course
Velo by Wix: Working with Data
Work with JavaScript collection types, arrays and objects and incorporate these skills into Velo.Beginner Friendly6 hours