var animal = {

name: “Buster”,

age: 6,

type: “Husky”,

colour: “blue”,

speak: function() {

console.log(”Woof”);

}

}

Now this might look a bit complex at first, but it’s actually extremely simple. Ignore the exact syntax for now and just glance over what is actually happening. We are simply assigning information to keywords. We are just entering data that we want to assign to a term. We are saying that we want the animal’s name to be Buster, and his type should be husky, etc. Then we are giving him a function to speak, which we are calling ‘speak’. Simple enough, right? Let’s break this down further one bit at a time and analyse the structure and syntax of an object.

So, first things first, you will notice we still use the var keyword followed by the name we want to call the variable, just like before. This variable is called ‘animal’, then we assign it to a piece of data, just like we have done previously. We use the = sign for this. After this things get a bit different. So to tell JavaScript that we want to create an object, we use curly braces, like so {}, then everything inside those curly braces is our object. You might also have noticed how defining an object spans over multiple lines, which is something we haven’t really seen before, but this is absolutely fine when creating an object and helps to create wonderful, readable code that’s easy to interpret and understand.

Now, an object is nothing more than a bunch of ‘name: value’ pairs. That is to say, we assign a value to a name of our choosing. Analysing the above example, let’s take a closer look at the following snippet of code: