Methods and Properties


In Object-Oriented Programming, objects store data and behavior together.

The data inside an object is called properties. 

The functions inside an object are called methods.

Understanding how properties and methods work together is essential for building useful and interactive objects in JavaScript.

Properties vs Methods

Properties

  • Store information  
  • Represent object data
  • Example: name, age, price  

Methods

  • Perform actions
  • Represent object behavior
  • Example: showInfo(), calculateTotal()  

Together, properties and methods define what an object is and what it can do.

Here, name, age, and city are properties of the user object.

They store information about the user.

The greet function is a method of the user object.

It uses the this keyword to access object properties.

These examples show how properties store data and methods define behavior.

By mastering methods and properties, students gain the ability to create meaningful and interactive objects that form the foundation of professional JavaScript applications.