JavaScript
31K subscribers
1.24K photos
10 videos
33 files
905 links
A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes!

Let's chat: @nairihar
Download Telegram
CHALLENGE

const sym = Symbol('id');
const target = { a: 1, [sym]: 2 };
Reflect.defineProperty(target, 'b', { value: 3, enumerable: false });

const handler = {
get(obj, prop, receiver) {
if (prop === 'a') return Reflect.get(obj, prop, receiver) * 10;
return Reflect.get(obj, prop, receiver);
}
};

const proxy = new Proxy(target, handler);
console.log(proxy.a, proxy.b, Reflect.ownKeys(target).length, Object.keys(target).length);
👍3🔥2
What is the output?
Anonymous Quiz
15%
1 3 3 1
36%
10 3 3 2
40%
10 3 3 1
9%
10 3 2 1
👍1🤔1
CHALLENGE

let a = 0;
let b = null;
let c = '';
let d;

a ||= 10;
b ??= 20;
c &&= 'changed';
d ??= a + b;

console.log(a, b, c, d);
❤2👍2🔥1🤔1
❤1
CHALLENGE

function build(a, b = a + 1, c = (() => a + b)()) {
a = 100;
return [a, b, c];
}
console.log(build(1), build(1, 2), build(5, 5, 5));
❤2👍1🤔1
CHALLENGE

let outerType;
{
function greet() {
return 'inner';
}
outerType = typeof greet;
}
console.log(outerType, typeof greet);
🔥4❤3👍1
❤5🔥3👍2
CHALLENGE

const x = 2n ** 10n;
const y = 7n / 2n;
const z = -7n / 2n;
const w = BigInt(3.0) === 3n;
console.log(`${x} ${y} ${z} ${typeof x} ${w}`);
❤5🤔3🔥1
CHALLENGE

const obj = { a: { b: null, getC: () => 42 } };
let calls = 0;
function sideEffect() {
calls++;
return 10;
}
const result = obj.a?.b?.getC?.() ?? sideEffect();
const result2 = obj.a?.z?.getC?.() ?? sideEffect();
console.log(result, result2, calls);
🤔5👍4🔥4❤3
🤔4🔥3❤1
CHALLENGE

const counter = {
count: 0,
*[Symbol.iterator]() {
yield this.count++;
yield this.count++;
yield this.count++;
}
};

console.log([...counter], counter.count);

export {};
🤔6🔥3👍2❤1
❤4🔥2🤔2👍1
😮 An Experimental 'Green Threads' Implementation for Node

James has opened a PR that adds a new, lightweight kind of worker that shares a small pool of OS threads, with each worker getting its own V8 isolate (but no Node APIs). His numbers show a thousand of them using about 1GB of memory vs 6.7GB for regular worker threads. Early days, but a promising idea that deserves feedback.

James M Snell
Please open Telegram to view this post
VIEW IN TELEGRAM
❤6👍3🔥2🤔1
CHALLENGE

function makeCounter() {
let count = 0;
return function increment(step = count++) {
return (count += step);
};
}
const counter = makeCounter();
console.log(counter(), counter(), counter(5));
🔥1
What is the output?
Anonymous Quiz
16%
0 2 7
36%
0 1 6
31%
1 3 8
17%
1 2 7
❤1
CHALLENGE

function* inner() {
yield 1;
yield 2;
return 100;
}

function* outer() {
const result = yield* inner();
yield result;
yield 3;
}

const it = outer();
console.log(it.next().value, it.next().value, it.next().value, it.next().value);
❤1