Created
June 7, 2021 16:53
-
-
Save dimasmiftah/93e138a7f3f065b27f1708ace6acd212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let manusia = { | |
| nama: 'Dimas', | |
| umur: 20, | |
| peliharaan: { | |
| ikan: 'Lemon', | |
| } | |
| } | |
| let klonManusia = {...manusia} | |
| console.log(manusia) | |
| // { | |
| // nama: 'Dimas', | |
| // umur: 20, | |
| // peliharaan: { | |
| // ikan: 'Lemon', | |
| // } | |
| // } | |
| // kita ubah nama dan ikan | |
| manusia.nama = 'Kirana' | |
| manusia.peliharaan.ikan = 'Leo' | |
| console.log(manusia) | |
| // { | |
| // nama: 'Kirana', | |
| // umur: 20, | |
| // peliharaan: { | |
| // ikan: 'Leo', | |
| // } | |
| // } | |
| // lihat apa yang terjadi pada klonManusia | |
| console. log(klonManusia) | |
| // { | |
| // nama: 'Dimas', <-- ✅ nama tidak terpengaruh | |
| // umur: 20, | |
| // peliharaan: { | |
| // ikan: 'Leo', <-- ❌ ikan ikut berubah | |
| // } | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment