Objects are variables that can store multiple related pieces of information as named properties. Each property has a name and a value.
Good reference to objects in JavaScript
We can create an object using the new Object() constructor:
const myPerson = new Object();
Click the button to create a person object and display its properties.
Object properties can be changed after the object has been created. Try changing the person's age!
If an object is declared inside a function using let or const, it is normally only accessible inside that function. Trying to access it outside the function will cause a ReferenceError.
Declaring an object outside a function allows multiple functions to access it. This is useful when several buttons need to interact with the same object.
However, global variables can cause naming conflicts. Keeping variables inside functions or using a shared object in a controlled scope is often better for larger projects.
Add a new property called favouriteGame to the object. Display it in showPerson(), then create a button that changes it.