In this lesson, you checked whether Monday’s meals changed between last week and next week, and found that === doesn’t compare what’s inside two arrays.
Key Points
- After the day-by-day copy,
nextWeek[0].mealsandlastWeek[0].mealshold the same two strings, yetnextWeek[0].meals === lastWeek[0].mealsisfalse. The copy built a new meals array, so there are two arrows to two arrays. - Between two arrays or objects,
===asks one question: do these two arrows point at the same object? Comparing which object two arrows reach is called comparing by identity. - Give one array a second name, as
const mondayMeals = lastWeek[0].meals;does, andmondayMeals === lastWeek[0].mealsistrue: two arrows, one array. ==asks the same question between two arrays, sonextWeek[0].meals == lastWeek[0].mealsisfalsetoo.- For arrays and objects,
.includes()checks each slot with the same question.lastWeek.includes(nextWeek[0])isfalse: next Monday looks exactly like last Monday, but the copy made it a new record.lastWeek.includes(lastWeek[0])istrue, because that slot holds an arrow to the real Monday. - Strings and numbers compare by value: last Monday’s dinner and a separately typed
"jollof rice"are===equal, solastWeek[0].meals[1] === "jollof rice"istrue. - The rule: between arrays or objects,
===asks whether two arrows reach the same object. It never looks at the contents.
Final Code
The final plan.js runs every check from the lesson: