1-6 Javascript Objects
Last updated
Last updated
An object is a collection of related data and/or functionality. This usually consists of several variables and functions, called properties and methods when they are inside objects.
Properties are the values associated with an object. They can usually be modified, added, and deleted.
Methods are the actions that can be performed on objects. They are properties containing a function definition.
This would all work the same in a video game. In a video game, you might have a character object. You can create as many versions of that character object as you need.
Properties of the character object could be hair style, skin color, clothing, eye color, weapon, special move, etc. Each of those properties would have a value:
This could all be combined in code like this:
The character would also have methods associated with it. The character could do things like walk, run, use their weapon, etc. It would look like this: