JavaScript Objects
JavaScript Objects 1. What is a JavaScript Object? JavaScript objects are collections of key-value pairs. Keys (or properties) are strings, while values can be of any data type (numbers, strings, arrays, functions, or even other objects). Objects are used to store structured data. 2. Creating an Object There are multiple ways to create an object in JavaScript: (a) Using Object Literal let student = { name: "John Doe", age: 20, course: "JavaScript", isEnrolled: true }; console.log(student.name); // Output: John Doe (b) Using the new Object() Constructor let employee = new Object(); employee.name = "Alice"; employee.salary = 50000; console.log(employee.salary); // Output: 50000 (c) Using a Constructor Function function Car(brand, model, year) { this.brand = brand; this.model = model; this.year = year; } let myCar = ...