JavaScript Objects in Telugu

JavaScript Objects

Introduction to Objects (Basics)

Object అంటే ఏమిటి?

JavaScript Object అనేది key-value pairsతో తయారైన ఒక structure.
ఒక object లో multiple data (like name, age, email) ఒకే చోట store చేయవచ్చు.

Syntax:

JavaScript
let person = {
  name: "Ravi",
  age: 25,
  email: "ravi@gmail.com"
};

Explanation:

  • name, age, email — ఇవి keys (properties)
  • "Ravi", 25, "ravi@gmail.com" — values

1.Object Creation & Properties

JavaScript
let person = {
    firstName: "Rahul",
    lastName: "Kumar",
    age: 25,
    city: "Hyderabad"
};

console.log(person.firstName + " " + person.lastName);

Output: Rahul Kumar

💡 Explanation:

  • person అనే objectను curly braces {} లో define చేసాము.
  • Object లో key-value pairs ఉంటాయి (e.g., firstName: "Rahul").
  • console.log(person.firstName) ద్వారా value ను retrieve చేసాము

2.Accessing Object Properties

JavaScript
console.log(person["city"]);  // Method 1
console.log(person.age);       // Method 2

Output: Hyderabad 25

Explanation:

  • Objects లోని data ని dot notation (.) లేదా bracket notation ([]) ద్వారా access చేయవచ్చు

3. Adding & Updating Properties

JavaScript
person.country = "India"; // Adding new property
person.age = 26; // Updating existing property
console.log(person);

Output: {firstName: "Rahul", lastName: "Kumar", age: 26, city: "Hyderabad", country: "India"}

💡 Explanation:

  • person.country = "India"; ద్వారా కొత్త property add చేసాము.
  • person.age = 26; ద్వారా existing value update చేసాము.

4. Object Methods (Functions inside Objects)

JavaScript
let car = {
    brand: "Toyota",
    model: "Camry",
    start: function() {
        return "Car Started!";
    }
};

console.log(car.start());

Output: Car Started!

Explanation:

  • Methods అనేవి Objects లో functions లాంటివి.
  • start method car.start() ద్వారా call చేసాము.

Leave a Reply

Your email address will not be published. Required fields are marked *