Created
June 7, 2021 16:44
-
-
Save dimasmiftah/1e8a063f066182dffc687f27afd4d691 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
// Kloning array | |
let kucing = ['leo', 'lui'] | |
let klonKucing = [...kucing] | |
console.log(kucing) | |
// ["leo", "lui"] | |
// kita ubah nilai kucing | |
kucing.push('darkness') | |
console.log(kucing) | |
// ["leo", "lui", "darkness"] | |
// ✅ nilai klonKucing tidak ikut berubah | |
console.log(klonKucing) | |
// ["leo", "lui"] | |
// Kloning object | |
let manusia = {nama: 'Dimas', umur: 20} | |
let klonManusia = {...manusia} | |
console.log(manusia) | |
// {nama: "Dimas", umur: 20} | |
// kita ubah nilai manusia | |
manusia.nama = 'Kirana' | |
console.log(manusia) | |
// {nama: "Kirana", umur: 20} | |
// ✅ nilai klonManusia tidak ikut berubah | |
console.log(klonManusia) | |
// {nama: "Dimas", umur: 20} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment