JAVASCRIPT Tutorial
Objects are data structures that organize data in a structured and meaningful way. They consist of:
object.key = value;
object['key'] = value;
object.key;
object['key'];
function
keyword to define methods inside the object:object.methodName = function() {...}
// Create an object to store person data
const person = {
name: 'John Doe',
age: 30,
greet: function() {
console.log(`Hello, my name is ${this.name}`);
}
};
// Access the 'name' property
console.log(person.name); // Output: 'John Doe'
// Call the 'greet' method
person.greet(); // Output: 'Hello, my name is John Doe'