Video Lesson

Lesson Notes

Basic Objects in JavaScript (Simple)

Objects in JavaScript store data as key–value pairs.

Creating an Object

1const obj = {};

Or with initial properties:

1const obj = { 2 firstName: "Edward", 3 age: 24, 4 cars: ["Audi", "BMW"], 5 siblings: { 6 sister: "Kim", 7 brother: "Jeremy" 8 } 9};

Accessing Properties

Dot Syntax

1console.log(obj.firstName); // "Edward" 2console.log(obj.age); // 24 3console.log(obj.siblings.brother); // "Jeremy"

Bracket Syntax

1console.log(obj["firstName"]); // "Edward" 2console.log(obj["siblings"]["sister"]); // "Kim"

Use bracket syntax when property names are dynamic or contain special characters:

1const specialObj = { 2 "!note": "This is an exclamation", 3 "1hello": "Starts with a number" 4}; 5 6console.log(specialObj["!note"]); // "This is an exclamation" 7console.log(specialObj["1hello"]); // "Starts with a number"

Values Can Be Anything

  • Primitives (string, number, boolean, null, undefined, Symbol)
  • Arrays
  • Other objects
  • Functions
1const mixed = { 2 text: "hello", 3 count: 3, 4 flag: true, 5 data: null, 6 items: [1, 2, 3], 7 nested: { a: 1 }, 8 fn: function() { console.log("I’m a function!"); } 9};

Summary

  • Objects group related data under named keys.
  • Use dot or bracket syntax to read/write properties.
  • Keys must be unique within the same object.
  • Values can be any valid JavaScript type.

AI Assistant

Sign In Required

Sign in and subscribe to use the AI assistant for instant help with your lessons.

Sign In

Basic Objects in JavaScript (Simple)

In this lesson, you'll discover the fundamentals of JavaScript objects, learning how to create, access, and manipulate data stored as key-value pairs. By the end, you'll be equipped to use both dot and bracket syntax to handle diverse data types, empowering you to manage complex structures with ease.

5m 8s

Course Content

0 of 32 lessons completed
6. Promises, Async and Await
0 of 0 completed
7. The DOM
0 of 0 completed