CHALLENGE
function tag(strings, ...values) {
// strings.raw preserves literal escape sequences
const rawParts = strings.raw;
let result = rawParts.join('|');
result += '::' + values.join(',');
return result;
}
const x = 5;
const output = tag`Line1\nLine2${x}End`;
console.log(output);❤4👍4🔥1
What is the output?
Anonymous Quiz
31%
Line1\nLine2|End::5
42%
Line1\nLine2,End::5
20%
Line1nLine2|End::5
7%
5::Line1\nLine2|End
🔥4
CHALLENGE
const config = { retries: 0, timeout: null, name: '' };
const a = config.retries || 5;
const b = config.timeout ?? 10;
const c = config.name || 'default';
const d = config.missing?.value ?? 'fallback';
let calls = 0;
const sideEffect = () => { calls++; return true; };
const e = config.retries && sideEffect();
console.log(a, b, c, d, e, calls);❤4👍2🔥2
What is the output?
Anonymous Quiz
34%
5 10 default fallback 0 0
30%
0 10 default fallback 0 0
24%
5 10 default fallback 1 1
12%
5 null default fallback 0 0
❤3🔥1
CHALLENGE
function tag(strings, ...values) {
return strings.raw.join('|') + '=' + values.reduce((sum, v) => sum + v, 0);
}
const x = 5;
const y = 10;
console.log(tag`Sum\n${x}and${y}end`);❤4👍1
What is the output?
Anonymous Quiz
37%
Sum\n|and|end=15
36%
Sum\n|and|end=105
18%
Sum|and|end=15
10%
Sum\n,and,end=15
🔥4❤3👍2
CHALLENGE
const order = [];
const log = (s) => order.push(s);
log('start');
Promise.resolve().then(() => {
log('p1');
return Promise.resolve();
}).then(() => log('p1-2'));
async function foo() {
log('foo-start');
await null;
log('foo-end');
}
foo();
Promise.resolve().then(() => log('p2'));
log('end');
setTimeout(() => console.log(order.join(' ')), 0);
❤4🔥1
CHALLENGE
const a = [] + {};
const b = {} + [];
const c = 1 + '1' - 1;
const d = '5' + 3 - 2;
const e = true + true;
console.log(a, b, c, d, e);👍5🤣3❤2🔥1
What is the output?
Anonymous Quiz
11%
0 0 10 51 2
28%
[object Object] [object Object] 10 51 1
53%
[object Object] [object Object] 10 51 2
9%
[object Object] 0 10 51 2
❤5👍3
CHALLENGE
let arr = [];
for (let i = 0; i < 3; i++) {
if (i === 1) {
let i = 10;
arr.push(i);
continue;
}
arr.push(i);
}
console.log(arr.join('-'));
❤4🔥4👍2
❤5🤔3
CHALLENGE
class Config {
constructor(options = {}) {
this.retries = options.retries ?? 3;
this.timeout = options.timeout ?? 1000;
}
}
const cfg1 = new Config({ retries: 0, timeout: null });
const cfg2 = new Config({ retries: undefined, timeout: false });
cfg1.retries ??= 99;
cfg2.timeout ??= 99;
console.log(cfg1.retries, cfg1.timeout, cfg2.retries, cfg2.timeout);❤2🔥1
What is the output?
Anonymous Quiz
20%
0 1000 3 99
53%
0 1000 3 false
16%
0 99 3 false
12%
99 1000 3 false
👍1
CHALLENGE
const Loggable = {
log() { return `[${this.constructor.name}] ${this.toString()}`; }
};
class Base {
toString() { return 'Base instance'; }
}
Object.setPrototypeOf(Base.prototype, Loggable);
class Derived extends Base {
toString() { return 'Derived instance'; }
}
const b = new Base();
const d = new Derived();
console.log(b.log(), d.log(), Object.getPrototypeOf(Derived.prototype) === Base.prototype);❤5🔥1
CHALLENGE
function 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 add = memoize((a, b) => { calls++; return a + b; });
const r1 = add(1, 2);
const r2 = add(2, 1);
const r3 = add(1, 2);
console.log(r1, r2, r3, calls);❤2
🔥2❤1
The newly expanded Next.js team (now including Dan Abramov and 𝕏 Pete Hunt!) has dropped the latest version of the popular React framework, complete with faster builds, optional TypeScript 7 type checking, faster SSR, Instant Navigations, AI improvements, and more.
The Next.js Team
Please open Telegram to view this post
VIEW IN TELEGRAM
🤔3❤1
CHALLENGE
const str = "2024-01-15";
const result = str.replace(/(\d+)-(\d+)-(\d+)/, "$3/$2/$1");
const s2 = "abc".padStart(6, "12");
const s3 = [..."hello"].reverse().join("");
console.log(result, s2, s3);
👍4❤1
What is the output?
Anonymous Quiz
30%
2024/01/15 12abc olleh
31%
15/01/2024 121abc hello
27%
15/01/2024 121abc olleh
12%
15/01/2024 abc121 olleh
👍2❤1