-
Notifications
You must be signed in to change notification settings - Fork 0
JavaScript: Procedural vs. OOP
John Verz edited this page May 9, 2025
·
1 revision
- Code is organized into functions and procedures.
- Focuses on what to do and the steps to do it.
- Data and behavior are separate.
let user = { name: "Ana", age: 20 };
function celebrateBirthday(user) {
user.age += 1;
}
- Step-by-step instructions.
- Simple and easy for small tasks.
- Can become messy as complexity grows.
- Code is organized around objects and classes.
- Focuses on what things are (objects) and what they do (methods).
- Data and behavior are bundled together.
class User {
constructor(name, age) {
this.name = name;
this.age = age;
}
celebrateBirthday() {
this.age += 1;
}
}
- Promotes encapsulation, abstraction, inheritance, and polymorphism.
- Easier to manage complex applications.
- Encourages code reuse and structure.
Feature | Procedural | OOP |
---|---|---|
Structure | Functions | Classes/Objects |
Focus | Actions | Entities + their behavior |
Data Handling | Separate from logic | Bundled inside objects |
Code Reuse | Less structured | Inheritance and composition |
Best For | Small scripts, step logic | Large apps, UI systems |