I am learning Javascript and in W3 schools' code editor I try the following code :
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var cars = ["Saab", "Volvo", "BMW"];
var newcars = [];
newcars = cars;
newcars[0] = "Benz"
document.getElementById("demo").innerHTML = cars[0];
</script>
</body>
</html>
I expected the value to be : "Saab" since I made no changes to the cars array and the only change was to the newcars array, yet the output was : "Benz".
Could someone please explain what is happening?
Thanks