const droid = {
name: 'R2-D2',
height: '1.08'
}
// define newDroid with droid reference
const newDroid = droid
// add some new attributes
newDroid.colors = ['blue', 'silver', 'white']
newDroid.productionInformation = {
manufacturer: 'Industrial Automaton',
productLine: 'R-series',
model: 'R2 series astromech droid'
}
// the original object is updated because the reference of newDroid is the same
console.log(droid)
// [object Object] {
// colors: ['blue', 'silver', 'white'],
// height: '1.08',
// name: 'R2-D2',
// productionInformation: [object Object] {
// manufacturer: 'Industrial Automaton',
// model: 'R2 series astromech droid',
// productLine: 'R-series'
// }
// }
// newDroid was updated by the reference
console.log(newDroid)
// [object Object] {
// colors: ['blue', 'silver', 'white'],
// height: '1.08',
// name: 'R2-D2',
// productionInformation: [object Object] {
// manufacturer: 'Industrial Automaton',
// model: 'R2 series astromech droid',
// productLine: 'R-series'
// }
// }
Created
March 20, 2021 13:24
-
-
Save darleykrefta/4be553f584b8737d2c6bf41d380051f0 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment