JAVASCRIPT Tutorial
Objects are fundamental in JavaScript, allowing you to store and manipulate data in a structured way. Creating objects is straightforward and involves the following steps:
"name": "John"
"greet": function() { return "Hello, " + this.name; }"
const person = {
name: "John",
age: 30,
greet: function() { return "Hello, " + this.name; }
};
console.log(person.name); // Output: John
console.log(person.greet()); // Output: Hello, John
const employee = {
name: "Jane Doe",
salary: 50000,
promote: function() { this.salary *= 1.1; }
};
employee.promote();
console.log(employee.salary); // Output: 55000
This example demonstrates creating an object with properties (name, salary) and a method (promote) that increases the salary by 10%.