let courses = [
{id:1, name : "Femin"},
{id:2, name : "Darsh"},
{id:3, name : "Smit"},
];
let enteredId = 2;
const course = courses.find(c => c.id === enteredId);
course.name = "Darsh Bhimani";
console.log(course);
console.log(courses);
So this is the code I've been working with. I have been working with Java and C,C++ for the past 5-6 years and started with Javascript a week back. (For node.js).
Now what I am finding confusing here are two things:
- The variable course is a constant, still its value can be changed. How ?
- The course is fetched from the array courses, but still on changing course, when I log courses, I see that the value of the array has also changed. How is that possible?
In this case it does not matter if the value changes, but when I don't want the array to change, what can I do?