Please open Telegram to view this post
VIEW IN TELEGRAM
👍3❤2🤣2🔥1
CHALLENGE
const base = { greet() { return 'hi'; } };
const obj = Object.create(base, {
x: { value: 1, enumerable: true },
y: { value: 2, enumerable: false }
});
const spread = { ...obj };
const assigned = Object.assign({}, obj);
console.log(
spread.x,
spread.y,
spread.greet,
assigned.y,
Object.keys(spread).length
);What is the output?
Anonymous Quiz
21%
1 2 hi 2 2
31%
1 undefined hi 2 1
40%
1 undefined undefined undefined 1
8%
1 2 undefined undefined 1
❤3
CHALLENGE
const wm = new WeakMap();
class Counter {
#id;
static #nextId = 0;
constructor() {
this.#id = Counter.#nextId++;
wm.set(this, { count: 0, id: this.#id });
}
inc() {
const data = wm.get(this);
data.count++;
return data.count;
}
}
const a = new Counter();
const b = new Counter();
a.inc(); a.inc();
b.inc();
console.log(`${a.inc()} ${b.inc()} ${wm.has(a)} ${wm.get(a).id} ${wm.get(b).id}`);
What is the output?
Anonymous Quiz
0%
4 2 true 1 0
33%
2 1 true 0 1
33%
3 2 false 0 1
33%
3 2 true 0 1