CHALLENGE
const sym1 = Symbol('id');
const sym2 = Symbol('id');
const obj = {
[sym1]: 'first',
[sym2]: 'second',
regular: 'value'
};
const s = Symbol.for('shared');
const s2 = Symbol.for('shared');
console.log(
sym1 === sym2,
Object.keys(obj).length,
Reflect.ownKeys(obj).length,
s === s2,
sym1.toString()
);β€1
What is the output?
Anonymous Quiz
28%
false 1 3 false Symbol(id)
41%
true 1 3 true Symbol(id)
24%
false 1 3 true Symbol(id)
7%
false 3 3 true Symbol(id)
π₯3β€2π1
CHALLENGE
function tag(strings, ...values) {
return strings.raw.join('|') + '::' + values.join(',');
}
const a = 5, b = 10;
console.log(tag`Sum:\n${a + b} End`);β€1π1
What is the output?
Anonymous Quiz
32%
Sum:\n| End::5,10
36%
Sum:\n End::15
24%
Sum:\n| End::15
9%
Sum: End::15
CHALLENGE
const a = -7 % 3;
const b = 7 % -3;
const c = 2 ** 3 ** 2;
const d = (2 ** 3) ** 2;
const e = 0.1 + 0.2;
console.log(a, b, c, d, e);
π₯1
What is the output?
Anonymous Quiz
15%
-1 1 512 64 0.3
50%
-1 1 512 64 0.30000000000000004
26%
-1 1 64 512 0.30000000000000004
8%
1 -1 512 64 0.30000000000000004
π1
CHALLENGE
async function main() {
const settled = await Promise.allSettled([
Promise.resolve(1),
Promise.reject('err'),
]);
const statuses = settled.map(s => s.status).join(',');
let anyResult;
try {
await Promise.any([Promise.reject('a'), Promise.reject('b')]);
} catch (err) {
anyResult = `${err.name}:${err.errors.join(',')}`;
}
console.log(statuses, anyResult);
}
main();CHALLENGE
const output = [];
output.push(typeof foo);
try {
output.push(typeof bar);
} catch (e) {
output.push(e.message);
}
var foo = () => 'foo';
let bar = () => 'bar';
console.log(output.join(' | '));
π€1
CHALLENGE
const arr = [1, [2, 3], [4, [5, 6]]];
const a = arr.flat();
const b = arr.flat(Infinity);
const c = arr.flatMap(x => Array.isArray(x) ? x : [x, x]);
console.log(a, b, c);
β€3
What is the output?
Anonymous Quiz
23%
[ 1, 2, 3, 4, [ 5, 6 ] ] [ 1, 2, 3, 4, 5, 6 ] [ [1,1], [2,3], [4,[5,6]] ]
38%
[ 1, 2, 3, 4, [ 5, 6 ] ] [ 1, 2, 3, 4, 5, 6 ] [ 1, 1, 2, 3, 4, [ 5, 6 ] ]
22%
[ 1, 2, 3, 4, [ 5, 6 ] ] [ 1, 2, 3, 4, 5, 6 ] [ 1, 2, 3, 4, [ 5, 6 ] ]
18%
[ 1, 2, 3, 4, 5, 6 ] [ 1, 2, 3, 4, 5, 6 ] [ 1, 1, 2, 3, 4, [ 5, 6 ] ]
β€1π₯1
CHALLENGE
function* inner() {
const x = yield 1;
yield x + 1;
return 100;
}
function* outer() {
const result = yield* inner();
yield result;
}
const g = outer();
console.log(g.next().value, g.next(10).value, g.next().value, g.next().value);β€1
What is the output?
Anonymous Quiz
19%
1 11 undefined 100
61%
1 11 100 undefined
11%
1 11 100 100
8%
1 10 100 undefined
π₯2β€1
CHALLENGE
const obj = {
value: 42,
getValue: function() {
return this.value;
}
};
const unboundGetValue = obj.getValue;
const boundGetValue = unboundGetValue.bind(obj);
const boundTwice = boundGetValue.bind({ value: 100 });
console.log(
boundGetValue(),
boundTwice(),
unboundGetValue.call({ value: 7 }),
obj.getValue.apply({ value: 99 })
);What is the output?
Anonymous Quiz
28%
42 42 7 99
44%
42 100 7 99
18%
42 42 42 42
10%
undefined 42 7 99
β€4
Maybe David Bushell saw the writing on the wall, as the Deno team isn't joining Cloudflare to keep working on Deno, but to fold celld into workerd so Durable Objects can be self-hosted (more on that here). The Deno runtime will get a final year of official fixes, Deno Deploy closes in six months, and JSR moves to Cloudflare's infrastructure.
Ryan Dahl
Please open Telegram to view this post
VIEW IN TELEGRAM
β€2π1π€1
CHALLENGE
class EventBus {
#listeners = new Map();
on(event, cb) {
if (!this.#listeners.has(event)) this.#listeners.set(event, []);
this.#listeners.get(event).push(cb);
return this;
}
emit(event, ...args) {
const cbs = this.#listeners.get(event) || [];
return cbs.map(cb => cb(...args));
}
}
const bus = new EventBus();
bus.on('data', x => x * 2).on('data', x => x + 1);
const results = bus.emit('data', 5);
console.log(results, bus.emit('missing', 1));β€2
What is the output?
Anonymous Quiz
17%
[ 10, 11 ] []
46%
[ 10, 6 ] undefined
35%
[ 10, 6 ] []
2%
[ 5, 6 ] []
π€©1
You might be wondering if the title of this article is a bit ambitious, but fear not! Iβve put in the time and effort to cover everything you need to know about the EventLoop in Node.js. And believe me, youβll discover so many new things along the way!
nairihar
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5π1