JavaScript
31.1K subscribers
1.22K photos
10 videos
33 files
894 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
What is the output?
Anonymous Quiz
25%
25 7
32%
9 36
32%
36 9
12%
16 5
1👍1🤩1
🔥
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥24🤣96🤩2👍1🤔1
CHALLENGE

const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);

const add = n => x => x + n;
const mul = n => x => x * n;

const composed = compose(add(3), mul(2));
const piped = pipe(add(3), mul(2));

console.log(composed(5), piped(5));
🔥41
What is the output?
Anonymous Quiz
15%
10 8
36%
8 10
25%
16 13
23%
13 16
🔥21👍1
CHALLENGE

const proto = { inherited: 'nope' };
const obj = Object.create(proto);
obj.b = 2;
obj[1] = 'one';
obj.a = 1;
Object.defineProperty(obj, 'hidden', { value: 'secret', enumerable: false });
obj[Symbol('sym')] = 'symbolValue';
console.log(
Object.keys(obj).join(','),
Object.values(obj).join(','),
Object.entries(obj).length
);
👍21🔥1
1👍1🔥1
CHALLENGE

function partial(fn, ...presetArgs) {
return (...laterArgs) => fn(...presetArgs, ...laterArgs);
}

const add = (a, b, c) => a + b + c;
const addFive = partial(add, 5);
const addFiveTen = partial(addFive, 10);
console.log(addFiveTen(1), addFive(2, 3));

export {};
3🔥3👍1
What is the output?
Anonymous Quiz
17%
16 5
35%
21 10
30%
10 16
18%
16 10
🔥3👍1
CHALLENGE

const nums = [40, 100, 1, 5, 25, 10];
nums.sort();
console.log(nums.join(' '));
3🤣3
CHALLENGE

class Range {
#start; #end;
constructor(start, end) { this.#start = start; this.#end = end; }
[Symbol.iterator]() {
let current = this.#start;
const end = this.#end;
return {
next() {
return current < end
? { value: current++, done: false }
: { value: undefined, done: true };
},
[Symbol.iterator]() { return this; }
};
}
}

const range = new Range(1, 5);
const arr1 = [...range];
const arr2 = [...range];
const sum = arr1.reduce((a, b) => a + b, 0);
console.log(arr1.join(','), arr2.join(','), sum);
1👍1
CHALLENGE

const log = [];

async function a() {
log.push('a-start');
await b();
log.push('a-end');
}

async function b() {
log.push('b-start');
await Promise.resolve();
log.push('b-end');
}

a();
log.push('sync-end');

setTimeout(() => console.log(log.join(',')), 0);
1🔥1
CHALLENGE

class Counter {
constructor() {
this.count = 0;
}
increment() {
this.count++;
return this.count;
}
}

const counter = new Counter();
const boundInc = counter.increment.bind(counter);
const rebind = boundInc.bind({ count: 100 });

console.log(boundInc(), rebind(), counter.count);
2👍2🔥2
What is the output?
Anonymous Quiz
37%
1 101 2
23%
1 2 1
25%
1 2 2
16%
1 1 1
🔥2
🌦 NestJS 12 Released with ESM-First Packages, Rspack and Vitest

The progressive framework gets its biggest release in years, going ESM-first (CJS is still an option), replacing webpack with Rspack, adding Standard Schema support for easy interop with Zod, Valibot and friends, plus structured logging, a brand new homepage, and more.

Kamil Mysliwiec
Please open Telegram to view this post
VIEW IN TELEGRAM
5🔥5👍2
CHALLENGE

class Base {
static count = 0;
static #secret = 42;
static {
Base.count = 10;
}
static getSecret() {
return this.#secret;
}
}

class Derived extends Base {
static count = Base.count + 5;
}

let result;
try {
result = Derived.getSecret();
} catch (e) {
result = e.constructor.name;
}

console.log(Base.count, Derived.count, result);
1👍1
4🔥3👍1
⛽️ Drydock: Diff Your npm Tarballs Before You Publish

From a Preact core team member comes a tool to diff built npm tarballs against the last published version, flagging install scripts, network access and new binaries. It can then gate your Actions publish job or watch npm's new staged publishing flow.

Jovi De Croock
Please open Telegram to view this post
VIEW IN TELEGRAM
👍42