Skip to content

Instantly share code, notes, and snippets.

@wentout
Last active October 27, 2020 22:27
Show Gist options
  • Save wentout/5d1d3e228d6e5c546b996959fa06d363 to your computer and use it in GitHub Desktop.
Save wentout/5d1d3e228d6e5c546b996959fa06d363 to your computer and use it in GitHub Desktop.
const or let question
'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