What is the output?
Anonymous Quiz
18%
k0,k1,k2 computed fromObj secret
45%
k1,k2,k3 overwritten fromObj secret
24%
k0,k1,k2 overwritten dyn secret
14%
k0,k1,k2 overwritten fromObj secret
👍3
CHALLENGE
const memoize = (fn) => {
const cache = new Map();
return (...args) => {
const key = JSON.stringify(args);
if (cache.has(key)) return cache.get(key);
const result = fn(...args);
cache.set(key, result);
return result;
};
};
let calls = 0;
const square = memoize((x) => {
calls++;
return x * x;
});
console.log(square(4), square(4), square(-4), calls);❤2
❤2
CHALLENGE
const handler = {
get(target, prop, receiver) {
if (!(prop in target)) {
return `no ${String(prop)}`;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value) {
if (typeof value === 'number' && value < 0) {
throw new RangeError('negative');
}
return Reflect.set(target, prop, value);
}
};
const obj = new Proxy({ a: 1, b: 2 }, handler);
obj.c = 10;
console.log(obj.a, obj.c, obj.missing, obj.hasOwnProperty('a'));❤3🔥2👍1
What is the output?
Anonymous Quiz
14%
1 10 no missing false
36%
undefined 10 no missing true
43%
1 10 no missing true
8%
1 10 undefined true
🔥5
CHALLENGE
let counter = 0;
const state = {
get value() {
counter++;
return counter % 3 === 0 ? null : counter;
}
};
let result;
result ??= state.value;
result ??= state.value;
result ??= state.value;
result ??= state.value;
console.log(result, counter);
❤3👍3🔥1
🔥3❤2
A Rust port of the Go-based TypeScript 7 compiler, built with some input from the TypeScript team and heading into Oxc. Benchmarks claim up to 8x the speed of TypeScript 7.0 and it runs in WebAssembly. Experimental, but npx tsrs works.
Chen, Mitropoulos and Nakazawa (Cloudflare / VoidZero)
Please open Telegram to view this post
VIEW IN TELEGRAM
❤4👍4🔥1
CHALLENGE
const s = "JavaScript";
const str = new String(s);
console.log(str === s, str == s, typeof str, str.at(-1), s.at(-1));
❤2👍1
What is the output?
Anonymous Quiz
29%
false true string t t
28%
true true string t t
28%
false true object t t
15%
false false object t t
❤1👍1🤣1
Still in alpha since last year, one of Leaflet's contributors has forked it, rolling in the 2.0 work plus rotation, fullscreen, search, heatmaps and more – all tree-shakeable.
Simon Legner
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥4❤2👍1🤔1
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🔥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
25%
1 2 hi 2 2
32%
1 undefined hi 2 1
33%
1 undefined undefined undefined 1
9%
1 2 undefined undefined 1
❤4
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}`);
❤1👍1
What is the output?
Anonymous Quiz
24%
4 2 true 1 0
33%
2 1 true 0 1
22%
3 2 false 0 1
22%
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 {};❤3