Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT DATA / CHAPTER 02 / Learn / LESSON 12
Eleventh class. Objects and arrays are passed by reference. Copying the name does not copy the data:
const a = [1]; const b = a; b.push(2); // a changes too
Shallow copies: [...arr], arr.slice(), Object.assign({}, obj). A push through an alias also changes the original; a push to the copy leaves the original length unchanged.
Print words like copy / same / changed to show the difference.
Common mistake: const copy = original for an object — that is the same reference.
Assigning an array copies the reference, not the data.
DATA STANDBY
›