JavaScript Objects
In this guide, you will learn the basics of object structure (Objects) in JavaScript.
How objects are created, differences in features and methods, data addition and deletion
and we will explain step by step how to travel with the for...in loop.
🎯 What You Will Learn in This Guide
- Difference between object literal (
{}) and constructor (new Object()) - Defining property and method
- Data access with period (
.) and square brackets ([]) - Adding, changing and deleting data to the object
- List object properties with loop
for...in
1️⃣ Introduction to JavaScript Objects
In JavaScript, an object consists of key and value pairs.
An object; It can contain different data types such as text, number, boolean or function (method).
A real-life example:
const kullanici = {
ad: "GenixNode",
yas: 5,
premium: true,
selamla: function() {
return `Merhaba, ben ${this.ad}!`;
}
};
The user object contains three properties (name, age, premium) and a method (greet). The this keyword represents the current object.
2️⃣ Properties and Methods
Concept Definition Analogy Property Represents the data of the object. Noun → Color of the car. Method: It is an object-specific function. Action (Verb) → Starting the car (start()).
Example:
const araba = {
marka: "Tesla",
renk: "kırmızı",
calistir: function() {
return `${this.marka} çalıştı!`;
}
};
The run() method is a specific behavior for the car object.
3️⃣ Object Creation Methods
🔹 Object Literal (Recommended Method)
const ayarlar = {};
🔹 Object Constructor
const ayarlar = new Object();
Both methods create empty objects, but they are both short and safe to use.
4️⃣ Accessing Features
Dot Notation
console.log(kullanici.ad);
Köşeli Parantez Gösterimi (Bracket Notation)
console.log(kullanici["yas"]);
The square bracket method is mandatory if the property name is stored in a variable or contains special characters.
Method Call
kullanici.selamla(); // "Merhaba, ben GenixNode!"
5️⃣ Add, Update and Delete Features
Add / Update
Kodu kopyala
kullanici.email = "info@ornek.com";
kullanici.premium = false;
Adding a New Method
kullanici.guncelle = function() {
return `${this.ad} bilgileri güncellendi.`;
};
Feature Deletion
delete kullanici.premium;
Returns true when the delete operation is completed successfully.
6️⃣ Looping in Object Properties (for...in)
for...in is used to loop over all keys in an object.
const karakter = {
isim: "Balta",
irki: "cüce",
yas: 139
};
for (let anahtar in karakter) {
console.log(`${anahtar.toUpperCase()}: ${karakter[anahtar]}`);
}
Output:
ISIM: Balta
IRKI: cüce
YAS: 139
Getting Keys as an Array with Object.keys()
console.log(Object.keys(karakter));
Output:
["isim", "irki", "yas"]
Object.keys() returns keys as an array, so you can work with methods like map() or forEach().
💬 Frequently Asked Questions (FAQ)
- What is the difference between object literal and constructor?
The literal() method is simple and preferred. new Object() is rarely used in special inheritance scenarios.
- What does the this keyword represent?
When inside a method, it shows the object that the method is bound to. For example, this.name accesses the name property on that object.
- When should I use square brackets?
If the property name contains spaces, special characters or variables. Example: object["email"] or object[prop].
- What is the difference between for...in and for...of?
for...in returns on object keys, and for...of returns on values in arrays or strings.
- Why are objects so important?
Because arrays, date objects, even DOM elements are actually objects. In other words, they are the basic building blocks of JavaScript.
🏁 Conclusion
JavaScript objects allow you to store data in an organized and related format. A user account, shopping cart or game character — they are all objects.
Using this information, you can develop more modular and manageable projects. 🚀 Test your applications on the GenixNode Platform and produce high-performance solutions with JavaScript objects.

