Objects
An object groups related data under named keys. A user, a product and an API response are all naturally objects. Arrays answer "which position?"; objects answer "which name?".
Creating and reading objects
Changing objects
conststops you from reassigning the variable, but you can still change the object's contents.
Safe access with ?.
Real data often has missing pieces. Optional chaining (?.) stops and returns undefined instead of crashing.
Methods and this
A function stored in an object is called a method. Inside it, this refers to the object.
Looping over objects
Destructuring and spread
JSON: objects as text
JSON is the text format that APIs use to send data. Converting between objects and JSON is an everyday task.
Practice: word counter
Count how many times each word appears in a sentence and print an object like { the: 2, cat: 1, ... }.
1.How do you read a key whose name is stored in the variable k?
2.What does user?.profile?.photo return if profile is missing?