PROGRAMMING-CONCEPTS

Properties: Definition, Purpose, and Examples

Properties are values stored inside objects, classes, or components that describe their characteristics or state. They behave like named fields you can read or update, and they often come with rules that control how those values are accessed or modified.

Properties allow you to represent real-world concepts—such as a user’s name, a product’s price, or a component’s state—in a structured and meaningful way.

Why Properties Matter

Properties make data easier to organize because they belong directly to the object or component that uses them.

Instead of scattering variables across a program, properties keep related information in one predictable place. They also allow you to control how data is changed, validate values, and ensure that objects maintain consistent internal state.

How Properties Work

A property consists of two main parts:

  • A name, which identifies the value
  • A storage mechanism, which holds the data

You may access a property directly, or through getters and setters that enforce rules about how the property behaves.

In some languages, properties can run logic whenever they’re read or updated. In others, they behave like simple fields without additional behavior.

Properties appear in objects, class instances, configuration objects, React components, Swift structures. The core idea remains: properties describe something about the object they belong to.

Examples

JavaScript: Object Properties

const user = {
  name: "Jana",
  age: 28
};

console.log(user.name);

The name and age properties store data related to the user object.

TypeScript: Typed Class Properties

class Course {
  title: string;
  duration: number;

  constructor(title: string, duration: number) {
    this.title = title;
    this.duration = duration;
  }
}

TypeScript enforces that each property matches the declared type.

Python: Properties With Getters and Setters

class Product:
    def __init__(self, price):
        self._price = price

    @property
    def price(self):
        return self._price

    @price.setter
    def price(self, value):
        if value < 0:
            raise ValueError("Price must be positive")
        self._price = value

Python uses the @property decorator to add logic when reading or updating values.

React: Component Props (Properties Passed From Parent)

function Greeting({ name }) {
  return <h1>Hello, {name}</h1>;
}

Props act as read-only properties that define how the component should behave or render.

Swift: Stored and Computed Properties

struct Score {
    var points: Int = 0
    var isHigh: Bool { points > 100 }
}

points stores data, while isHigh computes a value dynamically.

Real-World Applications

Properties play a central role in every part of software development because they model the data your app relies on. You encounter them in:

  • User profiles: name, email, role, preferences
  • E-commerce products: price, stock, category, rating
  • Configuration objects: API endpoints, feature flags, timeouts
  • React components: props and state values that shape UI output
  • Backend models: Python or TypeScript classes mapping to database fields
  • SwiftUI views: stored values representing UI state
  • API responses: structured JSON objects with property/value pairs
  • Database records: each row contains properties that define the stored entity
  • Validation workflows: enforcing rules on how properties can change
  • Serialization: converting properties into JSON for APIs or saving state

Because real-world entities always have attributes, properties become the backbone of data modeling.

Common Mistakes and Misconceptions

Properties look simple, but misunderstandings often lead to bugs or hard-to-maintain code. Some common issues include:

  • Confusing properties with variables. Variables belong to the current scope; properties belong to objects or classes.
  • Allowing unrestricted mutation. Without encapsulation, properties become difficult to control or validate.
  • Duplicating property names. Reusing names across nested structures creates ambiguity and confusion.
  • Writing unnecessary getters/setters. Some beginners wrap every property in a function even when direct access is simpler.
  • Not understanding read-only vs. writable properties. For example, React props cannot be changed inside the component.
  • Mixing computed and stored properties. These behave differently and should serve clear purposes.
  • Assuming property order matters. In most languages, property order in objects is not guaranteed to remain stable.
  • Relying on implicit property creation. Accidentally adding new properties at runtime can create unpredictable behavior.
  • Ignoring type constraints. Especially in TypeScript and Swift, incorrect property types cause runtime and compile errors.
  • Overloading a single object with too many properties. This usually signals that the object should be split into multiple models.

Understanding these pitfalls leads to cleaner, safer data modeling across your application.

Summary

Properties store information inside objects, classes, components, and database records. They define the attributes that describe an entity and can include logic that controls how values are read or updated.

Learn to Code for Free
Start learning now
button icon
To advance beyond this tutorial and learn to code by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.