Running the JS code below yields unexpected results in the console. Despite the console.log
statement being written before a line that changes a value, the output displays the changed value. This behavior goes against my expectations, as I would assume changes to only be reflected if another console.log(courses)
was added after courses[1].course="JS4"
.
const courses = [
{ teacher: "X", course: "JS" },
{ teacher: "X2", course: "JS2" }
];
courses.push({ teacher: "X3", course: "JS3" });
console.log(courses);
courses[1].course = "JS4";