100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Objects in JavaScript: A Complete Guide with Examples

Rating
-
Sold
-
Pages
6
Uploaded on
27-01-2025
Written in
2024/2025

This document covers objects in JavaScript, including how to create, access, and manipulate them. Learn about key-value pairs, methods, and advanced features like nested objects with clear examples.










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
January 27, 2025
Number of pages
6
Written in
2024/2025
Type
Other
Person
Unknown

Subjects

Content preview

Objects in JavaScript
Objects in JavaScript are collections of key-value pairs. They are one of the most
important data structures and are used to represent and manipulate complex
data.

1. Creating Objects
Object Literal

The simplest way to create an object.

const person = {
name: "Alice",
age: 25,
greet: function() {
console.log(`Hello, my name is ${this.name}`);
}
};
person.greet(); // Output: Hello, my name is Alice

Object Constructor

Uses the Object class to create an object.

const person = new Object();
person.name = "Bob";
person.age = 30;
console.log(person); // Output: { name: 'Bob', age: 30 }

Using a Function Constructor

Defines a reusable blueprint for creating similar objects.

function Person(name, age) {
this.name = name;
this.age = age;
this.greet = function() {

, console.log(`Hello, my name is ${this.name}`);
};
}
const alice = new Person("Alice", 25);
alice.greet(); // Output: Hello, my name is Alice

Using Object.create

Creates an object with a specified prototype.

const prototype = { greet() { console.log("Hello!"); } };
const obj = Object.create(prototype);
obj.greet(); // Output: Hello!


2. Accessing Properties
Dot Notation

console.log(person.name); // Output: Alice

Bracket Notation

Used when property names are dynamic or contain special characters.

console.log(person["name"]); // Output: Alice

Dynamic Property Names

const prop = "age";
console.log(person[prop]); // Output: 25


3. Modifying Properties
Add, update, or delete properties dynamically.

person.location = "New York"; // Adding
person.age = 26; // Updating
$5.69
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
rileyclover179

Also available in package deal

Thumbnail
Package deal
Complete JavaScript Complete Study Bundle with Q&A & Exam Guide (16 documents)
-
16 2025
$ 101.04 More info

Get to know the seller

Seller avatar
rileyclover179 US
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
11 months
Number of followers
0
Documents
252
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions