Nearby lessons

35 of 40

📦 JavaScript Objects & Const Usage

📌 What are JavaScript Objects?

JavaScript Object is a non-primitive data type used to store collections of key-value pairs. It can hold properties (data) and methods (functions).

JavaScript is object-based — everything is treated as an object.

🔸 Object Creation Methods

1. Object Literal: Directly define key-value pairs using curly braces.
2. Object Instance: Use the new Object() syntax.
3. Object Constructor Function: Use a function with this to assign properties.
Example02
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 JavaScript Array of Objects

Arrays can hold multiple objects. Each object can contain various properties.
Example03
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 const with Arrays

const allows array modification (like push()), but not reassignment.

You can change the contents, but not reassign the variable itself.

Example04
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 const with Objects

Like arrays, objects declared with const can have their properties updated.

But reassigning the object is not allowed.

Example05
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

10 Questions
Progress: 0 / 10