Property
A named value on an object.
Properties store values. Methods store behavior on an object. Together they let an object describe state and actions.
const panel = {
title: "Dashboard",
open() {
return `${this.title} opened`;
}
};
Objects, Prototypes & Classes
A property is a key-value pair. The value can be a string, number, boolean, array, object, function or any other JavaScript value.
A method is a function stored on an object. Method syntax is shorter than writing name: function () {}, and it gives this a useful meaning when called as object.method().
Keep properties and methods close to the data they work with, but do not turn every object into a large module. Small, focused objects are easier to reason about.
A named value on an object.
A function value called through the object.
Inside a method call, this usually points to the object before the dot.
Property and method shorthand reduce repetition.
Examples
const toggle = {
active: false,
switch() {
this.active = !this.active;
return this.active;
}
};
const switchToggle = toggle.switch; switchToggle(); // The method no longer has the same this context.
Code patterns
These patterns focus on the pieces developers actually reuse: object literals, methods, constructors, prototypes, getters, copying, classes and inheritance.
Use the variable name as the property name.
const name = "User A";
const role = "editor";
const profile = { name, role };
Use concise method syntax for object behavior.
const status = {
label: "Ready",
show() {
return this.label;
}
};
Build a property name from a value.
const field = "status";
const record = {
[field]: "ready"
};
A method can read other properties through this.
const counter = {
count: 0,
next() {
this.count += 1;
return this.count;
}
};
Rules that matter
Objects are where JavaScript programs start to model real application state. Good object shape makes later functions, classes and UI updates much easier to maintain.
Properties usually describe data.
Methods usually perform or calculate something.
It reads cleanly and works well with this.
Detached methods can lose this.
They are useful, but can hide structure if overused.
Too many methods can mean the object needs to be split.
Production thinking
Properties and methods are how JavaScript objects become models of state plus behavior.
Methods that update UI state should keep accessible labels and attributes in the same state model.
Production objects should expose clear methods instead of requiring other code to change internal details everywhere.
Objects with methods can prepare content consistently before it is rendered as headings, links or metadata.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Object-oriented JavaScript becomes much easier when you can explain where the data lives, where the method is found and which object receives this.