Objects are used to represent real world objects in programming
Within an object, variables are known as properties and functions are known as methods
Curly braces are a means of identifying if a variable is an object
// create an object that represents a dog
var myDog = {
name: "Fido",
age: 4,
speak: function() {
console.log('Woof woof');
}
}
In the example above, we created an object and stored it in a variable called myDog
This object has 2 properties (name and age) and 1 method (speak)
This of method as actions that our objects can take
var myDog = {
name: "Fido",
age: 4,
speak: function() {
console.log('Woof woof');
}
}
// store myDog's name in a variable called dogName
var dogName = myDog.name;
// call the speak method of myDog
myDog.speak();
Think of method as actions that our objects can take Like arrays, objects are another flexible and powerful feature of Javascript. Click here for more information about Objects