Passing objects by reference in JavaScript

Arrays and objects are somewhat different from other primitive data types. The difference is that the variable that stores array, does not actually contain it, but simply refers to it.

In practice, this means that when writing an object to another variable, both variables will refer to the same object. Let's try it in practice. Let's have the following object:

javascriptlet obj1 = {a: 1, b: 2, c: 3};

Assign it from one variable to another:

javascriptlet obj2 = obj1;

Let's change one of the variables:

javascriptobj2.a = '!';

As a result, the changes will be visible in the other variable as well:

javascriptconsole.log(obj1); // {a: '!', b: 2, c: 3}
Задание 1

Without running the code, determine what will be output to the console:

javascriptlet arr1 = [1, 2, 3];
let arr2 = arr1;

arr1[0] = 'a';
console.log(arr2);
Задание 2

Without running the code, determine what will be output to the console:

javascriptlet arr1 = [1, 2, 3];
let arr2 = arr1;

arr1[0] = 'a';
arr2[1] = 'b';

console.log(arr1);
Задание 3

Without running the code, determine what will be output to the console:

javascriptlet arr1 = [1, 2, 3];
let arr2 = arr1;

arr1[0] = 'a';
arr2[0] = 'b';

console.log(arr2);