Topics Covered in This JavaScript Tutorial:
Introduction to Objects, Defining Custom Objects, Accessing and Manipulating Object Properties
Exercise Preview

Exercise Overview
In this hands-on exercise, you'll master the fundamentals of JavaScript objects—one of the most crucial concepts for modern web development. You'll build custom objects from scratch and discover how to manipulate their properties dynamically, skills essential for creating interactive applications and managing complex data structures.
This tutorial combines theory with practical exercises. You'll work directly in the browser console to see immediate results and build muscle memory for object manipulation.
JavaScript Objects
JavaScript is fundamentally an object-oriented language where nearly everything you interact with is an object. Think of an object as a container that holds related data and functionality together. Each piece of data stored in an object is called a property, structured as key-value pairs—the key acts as the property name, while the value holds the actual data.
When a property's value is a function, we call it a method, giving objects the power to both store data and perform actions. This structure mirrors real-world entities perfectly: imagine a car object containing properties like doors, color, and seats, along with methods like start() and stop(). This natural mapping from reality to code makes JavaScript objects incredibly intuitive for modeling complex systems.
JavaScript is an object-oriented language because nearly everything is an objectObject Components
Properties
Name-value pairs that store data. Each property has a key and an associated value of any data type.
Methods
Special properties where the value is a function. Methods define what actions an object can perform.
Getting Started
Let's set up your development environment to explore JavaScript objects using modern browser tools.
- Navigate to the Objects folder located in Desktop > Class Files > JavaScript Class. Open this entire folder in your code editor—most modern editors like Visual Studio Code, WebStorm, or Sublime Text support folder-based workflows for better project organization.
- In your code editor, open js-objects.html from the Objects folder.
Preview js-objects.html in Chrome or any Chromium-based browser like Edge or Brave. We'll leverage the powerful DevTools built into these browsers for real-time JavaScript debugging and testing.
While the page appears minimal, the real action happens in the Console—your direct line to the JavaScript engine.
Keep this browser tab open throughout the exercise. You'll be refreshing it frequently to test your code changes, a fundamental part of the iterative development process.
Setup Process
Open Project Folder
Navigate to Desktop > Class Files > JavaScript Class > Objects folder in your code editor
Open HTML File
Launch js-objects.html from the Objects folder in your code editor
Preview in Browser
Open the HTML file in Chrome browser to access DevTools Console
Defining an Object
Now we'll create your first custom JavaScript object using modern ES6+ syntax and best practices.
- Return to your code editor to begin writing JavaScript.
Within the script tag, declare a variable to hold your object using the preferred
letkeyword:<script> let person = {}; </script>NOTE: The variable name person follows JavaScript naming conventions—descriptive and camelCase. The empty curly braces
{}create an object literal, the most common and efficient way to define objects in modern JavaScript.Add your first property inside the curly braces:
let person = { name: 'Bob' };NOTE: You've just created a key-value pair where name is the key (property name) and 'Bob' is the value. Property names should start with a letter and follow camelCase convention for multi-word properties. Values can be any JavaScript data type—strings, numbers, booleans, arrays, functions, or even other objects.
- Save your file and refresh the Chrome page to load your new JavaScript code.
- Open the Developer Console using Cmd–Opt–J (Mac) or Ctrl–Shift–J (Windows). The Console is your interactive JavaScript playground—use it extensively for testing and debugging.
In the Console, type
personand press Enter.The Console displays
{name: 'Bob'}, confirming your object exists and contains the expected property.
Object names can be anything as long as they don't start with a number. Use descriptive names that reflect what the object represents.
Object Creation Steps
Create Empty Object
Initialize with let person = {} using curly braces
Add First Property
Insert name: 'Bob' inside the curly braces
Test in Console
Verify object creation by typing person in browser console
Working with Properties of an Object
Master the essential techniques for accessing and modifying object properties—skills you'll use constantly in real-world development.
Test dot notation syntax to access individual properties. Type:
person.namePress Enter to execute.
The Console returns
'Bob'—notice how dot notation extracts just the value, not the entire key-value pair.- Switch back to your code editor to expand the object with additional data types.
Add a numeric property, separating multiple properties with commas:
let person = { name: 'Bob', age: 23 };NOTE: While you could write everything on one line, spreading properties across multiple lines dramatically improves readability—especially important when working with complex objects in production code.
Include a boolean property to demonstrate JavaScript's type flexibility:
let person = { name: 'Bob', age: 23, alive: true };NOTE: Boolean values are either true or false (no quotes needed). They're crucial for conditional logic and state management in applications.
- Save and refresh the page to load your enhanced object.
- Ensure the Console remains open (or reopen it with Cmd–Opt–J / Ctrl–Shift–J).
Inspect the complete object by typing
personand pressing Enter.The Console now displays all three properties: name, age, and alive, demonstrating how objects organize related data.
Access the boolean property specifically by typing
person.aliveand pressing Enter.The Console returns true, showing how you can extract any individual property value.
Add a new property dynamically—a powerful JavaScript feature for runtime object modification:
person.hairColor = 'brown'NOTE: This demonstrates JavaScript's dynamic nature. Unlike statically-typed languages, you can add properties to objects at any time during execution—invaluable for building flexible, responsive applications.
Press Enter to execute the assignment.
The Console echoes
'brown', confirming the property addition.- Verify the new property exists by typing
person.hairColorand pressing Enter. - Display the complete updated object by typing
personand pressing Enter. Notice how the hairColor property now appears alongside the original properties. Modify an existing property value to simulate real-world data updates:
person.age = 24Press Enter, then type
personand press Enter again to confirm the age property updated to 24.This demonstrates how objects serve as mutable data containers—essential for tracking changing application state.
Property Data Types Used
Property Access Methods
Dot Notation
Use person.name to access the name property and retrieve its value
Dynamic Addition
Add new properties directly: person.hairColor = 'brown'
Property Updates
Modify existing values: person.age = 24 to update age property
Code written directly in the browser Console is temporary and will be lost when you reload the page. Use it only for testing purposes.
JavaScript is Object-Oriented
While creating custom objects provides tremendous flexibility, remember that JavaScript's entire ecosystem revolves around objects. The DOM (Document Object Model) treats every HTML element as an object with properties and methods you can manipulate. When you use getElementById(), you're retrieving an object representing that HTML element, complete with properties like innerHTML, style, and classList.
This object-oriented foundation extends throughout the JavaScript runtime environment. In Class Files > JavaScript Class > Objects, you'll find two dom PDF files (basic and detailed versions) illustrating the hierarchical structure of browser objects.
Understanding this hierarchy is crucial for modern web development:
- The window object serves as the global container—representing the browser window itself and providing access to everything from local storage to geolocation APIs.
- Within the window, the document object represents your HTML page, providing methods to find, create, and modify elements. This is where most of your JavaScript programming takes place when building interactive web applications.
Built-in JavaScript Objects
Window Object
The topmost global object representing the browser window. Contains all other objects and global variables.
Document Object
Lives within the window object and represents the HTML document. Where you'll work with HTML elements.
HTML Elements
Each HTML element becomes an object in JavaScript with properties you can get and set using methods like getElementById.
Everything in JavaScript exists within the window object hierarchy. Understanding this structure is key to effective DOM manipulation and web development.