let myString = `brian` // attributes (properties) // we access the properties of an object by using the dot notation and the name of the property myString.length // => 5 // behaviors (methods) // we access the methods of an object by using the dot notation with parentheses myString.toUpperCase() // => `BRIAN`
To elaborate on the difference between properties and methods – for example, if we had a "car" object, it could have properties like color (red), make (Toyota), model (Prius); and it could have methods like "drive" or "park". Properties describe an object's attributes, and methods are a way to ask an object to do something, or return an output.
Let's create an object. This object will only feature properties for now – we'll get to creating an object's methods later.
An Array is a special type of Object that is meant to hold lists of information. We define an Array using the square brackets –  – then we have access to its elements, properties, and methods.
let burgerIngredients = [`buns`, `ground beef`, `american cheese`] // getting or setting value - zero-based burgerIngredients // => `ground beef` burgerIngredients // => undefined burgerIngredients = `ground chuck` burgerIngredients // => `ground chuck` // array properties burgerIngredients.length // => 3 // array methods output = burgerIngredients.sort() // => [`american cheese`, `buns`, `ground chuck`] burgerIngredients.push(`ketchup`) burgerIngredients.length // => 4
Basic objects and arrays (and later, methods/functions) are meant to be used in conjunction with each other, to ultimately define more complex objects used in our applications. For example, if we were building a simple social networking application, we might define an object that looks like this:
Just to have a taste of what something like this would work in practice – this object might be generated by a back-end API or come from a database of some kind. A front-end developer would be tasked with retrieving this object and traversing its structure in order to grab the pieces of data needed for the user interface.