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
const 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 two (2) properties (name and age) and 1 method (speak)
const myDog = {
name: "Fido",
age: 4,
speak: function() {
console.log('Woof woof')
}
}
// store myDog's name in a variable called dogName
const dogName = myDog.name
// call the speak method of myDog
myDog.speak()
Think of methods as actions that our objects can take. Objects are another flexible and powerful feature of JavaScript. Click here for more information about Objects