top of page

Objects

Objects allow you store a lot of different information and variables in one place. To create an object you create a variable with braces "{}" and what you would have assigned as separate variables you now write as properties using colons and commas (see example.) Each property has a key, which is on the left of the colon, and a value, which is on the right of the colon. You can store numbers, strings, arrays, booleans or even other objects as properties within an object. To call a property of an object you write the name of the object followed by a full-stop and then the key of the property, no spaces. We can also use "bracket notation", which looks similar to how we access array elements, where we write the variable name, then square brackets, with the property name inside in quotes. You can also write while and for loops using objects. Additionally, you can use an object to store two or more properties and then have an array to store multiple iterations of these objects.

Good additional information: Function and Object definitions end with a curly bracket followed by a semicolon. Other statements like for, while, if, switch, etc. end with a curly bracket only. Never write property names with white spaces but if you ever have to you can do so as long as you put "quotation marks" around them. There is also something called syntactic sugar which seems to make things easier when writing code. I need to look into this further. Edit: I wasn't happy with my current understanding of hot syntactic sugar and objects in arrays worked so I made a program to explore it. See also: Project: Bookshelf.

 
A table of code associated with objects.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • LinkedIn Social Icon
  • Pinterest Social Icon
  • Facebook Basic Square

© 2023 by Coming Soon

Proudly created with Wix.com

bottom of page