Objects

Almost everything in Javascript is either an object or can be treated as one.

Objects have properties and methods. Properties are like variables that belong to the object. Methods are something the object can do, or can be done to the object.

Example:

let person = {
            name: 'crap',
            surname: 'Smith',
            age: 32,
            hair:  'brown'
        };
        

There are two ways to construct an object in JavaScript:

  1. The object literal, which uses curly braces (as above).
  2. The object constructor, which uses the new keyword

The first, object literal, method is the preferred.

Here's an object containing a function or method

let pig = { 
    name: 'piggey', 
    age: '30', 
    colour: 'pink', 
    greet: function() { alert('ho ho ho!') },
    };

To access a property of an object use dot notation:

alert(person.name)

This is important when you think about syntax like:

document.title or

document.getElementById('h1')

These are objects too. Following the period is not necessarily a name(key). Objects also contain methods which are functions contained within an object. [More at Digital Ocean] ?

Loops

warWords.forEach(function(warWord) { alert(warWord); })