-
The most important thing about objects is to remember that they're just another variation of variables.
-
Here is a quick example of an object:
var choosePill = {
pillOne: 'Red',
pillTwo: 'Blue'
}
- Here's a table displaying the code object we just wrote:
Property | Stored Value |
---|---|
pillOne | Red |
pillTwo | Blue |
- Even though we only stored strings (you can remember strings based on the quotations), we can also store numbers. Here is our same code, updated:
var choosePill = {
pillOne: 'Red',
pillTwo: 'Blue',
numberOfPills: 2
}
var choice = choosePill.pillOne; // This will access the Objects property
Property | Stored Value |
---|---|
pillOne | Red |
pillTwo | Blue |
numberOfPills | 2 |