Skip to main content
March 23, 2026Dan Rodney/6 min read

JavaScript Objects: Free JavaScript Tutorial

Master JavaScript Objects with Interactive Coding Examples

What You'll Learn

Object Fundamentals

Understand what JavaScript objects are and why they're essential in modern web development. Learn the key-value pair concept.

Object Creation

Practice defining objects using literal notation and adding properties with different data types.

Property Manipulation

Master accessing, modifying, and adding object properties using dot notation and dynamic assignment.

Topics Covered in This JavaScript Tutorial:

Introduction to Objects, Defining Custom Objects, Accessing and Manipulating Object Properties

Exercise Preview

preview objects

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.

Hands-On Learning Approach

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 object
Understanding this fundamental concept is crucial for JavaScript mastery

Object 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.

  1. 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.
  2. In your code editor, open js-objects.html from the Objects folder.
  3. 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.

  4. 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

1

Open Project Folder

Navigate to Desktop > Class Files > JavaScript Class > Objects folder in your code editor

2

Open HTML File

Launch js-objects.html from the Objects folder in your code editor

3

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.

  1. Return to your code editor to begin writing JavaScript.
  2. Within the script tag, declare a variable to hold your object using the preferred let keyword:

    <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.

  3. 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.

  4. Save your file and refresh the Chrome page to load your new JavaScript code.
  5. 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.
  6. In the Console, type person and press Enter.

    The Console displays {name: 'Bob'}, confirming your object exists and contains the expected property.

Object Naming Convention

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

Step 1

Create Empty Object

Initialize with let person = {} using curly braces

Step 2

Add First Property

Insert name: 'Bob' inside the curly braces

Step 3

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.

  1. Test dot notation syntax to access individual properties. Type:

    person.name

  2. Press Enter to execute.

    The Console returns 'Bob'—notice how dot notation extracts just the value, not the entire key-value pair.

  3. Switch back to your code editor to expand the object with additional data types.
  4. 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.

  5. 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.

  6. Save and refresh the page to load your enhanced object.
  7. Ensure the Console remains open (or reopen it with Cmd–Opt–J / Ctrl–Shift–J).
  8. Inspect the complete object by typing person and pressing Enter.

    The Console now displays all three properties: name, age, and alive, demonstrating how objects organize related data.

  9. Access the boolean property specifically by typing person.alive and pressing Enter.

    The Console returns true, showing how you can extract any individual property value.

  10. 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.

  11. Press Enter to execute the assignment.

    The Console echoes 'brown', confirming the property addition.

  12. Verify the new property exists by typing person.hairColor and pressing Enter.
  13. Display the complete updated object by typing person and pressing Enter. Notice how the hairColor property now appears alongside the original properties.
  14. Modify an existing property value to simulate real-world data updates:

    person.age = 24
  15. Press Enter, then type person and 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

String50%
Number25%
Boolean25%

Property Access Methods

1

Dot Notation

Use person.name to access the name property and retrieve its value

2

Dynamic Addition

Add new properties directly: person.hairColor = 'brown'

3

Property Updates

Modify existing values: person.age = 24 to update age property

Console Testing Limitation

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.

Object Hierarchy

Everything in JavaScript exists within the window object hierarchy. Understanding this structure is key to effective DOM manipulation and web development.

Key Takeaways

1JavaScript objects are collections of key-value pairs that can represent complex real-world entities
2Objects are created using curly braces {} and can contain properties of any data type including strings, numbers, and booleans
3Dot notation (object.property) is the primary method for accessing and modifying object properties
4Properties can be added dynamically to existing objects using assignment syntax
5Methods are special properties where the value is a function that defines object behavior
6Nearly everything in JavaScript is an object, including HTML elements and built-in browser components
7The window object is the global container that holds all other objects in the browser environment
8Understanding object-oriented principles in JavaScript is essential for effective DOM manipulation and web development

RELATED ARTICLES