Last active
October 27, 2020 22:27
-
-
Save wentout/5d1d3e228d6e5c546b996959fa06d363 to your computer and use it in GitHub Desktop.
const or let question
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
'use strict'; | |
let toBeProp = 5; | |
const myObject = {}; | |
Object.defineProperty(myObject, 'prop', { | |
get () { | |
return { | |
[Symbol.toPrimitive] () { | |
return toBeProp; | |
} | |
}; | |
}, | |
enumerable: true, | |
}); | |
// const or let ??? | |
const { prop: prop1 } = myObject; | |
let { prop: prop2 } = myObject; | |
console.log(prop1 + 0); // 5 | |
console.log(prop2 + 0); // 5 | |
toBeProp = 7; | |
console.log(prop1 + 0); // 7 | |
console.log(prop2 + 0); // 7 | |
prop2 = 3; | |
console.log(prop1 + 0); // 7 | |
console.log(prop2 + 0); // 3 | |
console.log(myObject.prop + 0); // 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment