While researching online about JavaScript arrays and their methods, I came across something that left me puzzled. Specifically, I was diving into the Array.reverse() method:
var numbers = [60, 50, 20, 30];
var value = numbers.reverse();
console.log(numbers); // [30, 20, 50, 60]
console.log(value); // [30, 20, 50, 60]
What baffled me was why did the original "numbers" array change in this case?
I found it confusing because a similar situation does not occur here:
var number = 3;
var value = number * 2;
console.log(number); // 3
console.log(value); // 6
It struck me that in the first example, I am working with arrays, while in the second one, just integers. So, why does the "number" variable get altered when manipulating the "value" variable in the first scenario, but it remains unchanged in the second case? What sets these two examples apart?