Search⌘ K

Programming with Objects

Explore the fundamentals of JavaScript objects, including how to create them and access their properties using both dot and indexed notation. Understand the differences between these methods and learn when indexed notation is necessary, especially for property names with special characters. This lesson prepares you to work confidently with objects in JavaScript programming.

Objects are fundamental concepts in JavaScript. You can create and setup objects in several ways, as this code snippet illustrates:

Javascript (babel-node)
// "Manual" setup
var car = new Object();
car.manufacturer = "Honda";
car.type = "FR-V";
// Setup with constructor function
var Car = function (manuf, type) {
this.manufacturer = manuf;
this.type = type;
}
var car1 = new Car("Honda", "FR-V");
// Setup with JSON
var car2 = {
manufacturer: "Honda",
type: "FR-V"
};

Each mode of setup results the same object semantically, a car that has a manufacturer and a ...