August 2017
Beginner
298 pages
7h 4m
English
In JavaScript, arrays and objects are passed by reference during an assignment. For example, open a new JSFiddle window and try the following code:
const a = [1,2,3,4];const b = a;b.push(5);console.log('Value of a = ', a);console.log('Value of b = ', b);
We are creating a new array b from array a. We then push a new value 5 into array b. If you look at the console, your output will be as follows:

Surprisingly, both arrays have been updated. This is what I meant by passing by a reference. Both a and b are holding the reference to the same array, which means updating either one of them will update ...
Read now
Unlock full access