I am learning to use Sets in JavaScript and noticed some odd behavior when going through the documentation.
let beverageSet = new Set();
beverageSet.add('Rum');
beverageSet.add('Tea');
beverageSet.add('OJ');
console.log(beverageSet); // returns Set [‘Rum’, ‘OJ’]
beverageSet.delete('Tea');
console.log(beverageSet); // returns Set [‘Rum’, ‘OJ’]
I know that hoisting pulls all variables to the top of the scope before executing code, but I have not seen anything showing that it would affect console.log()/methods called on arrays and Sets.
Is this an effect of hoisting or something else? How can I get around this and console.log() the full Set before deleting an item and then console.log() again?