I am new to javascript. Coming from a more object oriented background, one quirk I noticed is that some methods override an array, and some others make new instances. For example:
// initialize array
var arr = [
"Hi",
"Hello",
"Bonjour"
];
// append new value to the original array
arr.push("Hola");
console.log(arr);
whereas concat
var arr = [
"apple",
"banana",
"cherry"
];
arr = arr.concat([ // original array needs to be overridden
"dragonfruit",
"elderberry",
"fig"
]);
console.log(arr);
Why is the behavior between the two methods not consistent?
Examples taken from: How to append something to an array?