15 minpresentation

Deep Cloning Strategies

Deep Cloning Strategies

0 / 6 completed

Shallow Copy Issues

typescript
1interface Address {
2 street: string;
3 city: string;
4}
5
6interface Customer {
7 name: string;
8 address: Address; // Nested object
9}
10
11const original: Customer = {
12 name: 'John',
13 address: { street: '123 Main', city: 'NYC' }
14};
15
16// Shallow copy - address is shared!
17const shallow = { ...original };
18shallow.address.street = '456 Oak';
19console.log(original.address.street); // '456 Oak' - MODIFIED!
Step 1 of 6
← → NavigateSpace: Skip / NextEnter: Next
Deep Cloning Strategies - Anko Academy