JavaScript Objects
In JavaScript, almost everything is an object. An object is a collection of related data and/or functionality. These usually consist of several variables and functions (which are called properties and methods when they are inside objects).
Object Literal Syntax
The easiest and most common way to create an object is using the object literal syntax. You define a set of comma-separated key-value pairs wrapped in curly braces {}.
Properties vs Methods
Data items placed inside objects are referred to as Properties. When a function is placed inside an object, it's called a Method. They define what the object knows and what it can do.
Dot and Bracket Notation
You can access properties using Dot Notation (object.property) which is clean and preferred, or Bracket Notation (object["property"]) which is necessary when keys are dynamic or contain spaces.
The this Keyword
Inside an object's method, the this keyword refers to the object itself. It allows the method to read and alter the object's own properties.
View Full Transcript+
This section covers detailed examples of object creation, using the this context safely, iterating over object keys using Object.keys() and standard for...in loops. Understanding objects is fundamental to understanding JavaScript's prototype-based inheritance model.
