CHALLENGE
const a = [] + [];
const b = [] + {};
const c = {} + [];
const d = 1 + "1" - 1;
const e = "5" - "2" + "3";
const f = [1, 2] == "1,2";
console.log(a, b, c, d, e, f);
🔥2🤩1
Please open Telegram to view this post
VIEW IN TELEGRAM
👍3❤2🔥2🤣2
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
26%
1 2 hi 2 2
27%
1 undefined hi 2 1
36%
1 undefined undefined undefined 1
11%
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
21%
4 2 true 1 0
41%
2 1 true 0 1
17%
3 2 false 0 1
21%
3 2 true 0 1
CHALLENGE
const createCounterModule = (() => {
let instances = 0;
return function() {
instances++;
let count = 0;
return {
increment() { count++; return count; },
id: instances
};
};
})();
const a = createCounterModule();
const b = createCounterModule();
console.log(a.increment(), a.increment(), b.increment(), a.id, b.id);
export {};❤1
CHALLENGE
const base = {
greet() { return `Hello, ${this.name}`; }
};
const mid = Object.create(base);
mid.name = 'Mid';
const child = Object.create(mid);
child.name = 'Child';
console.log(
child.greet(),
mid.greet(),
Object.getPrototypeOf(child) === mid,
child.hasOwnProperty('greet')
);