JavaScript
30.9K subscribers
1.23K photos
10 videos
33 files
904 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

async function fetchData(id) {
if (id <= 0) throw new Error("Invalid ID");
return { id, value: id * 10 };
}

async function process() {
const results = await Promise.allSettled([
fetchData(1),
fetchData(-1),
fetchData(3),
]);

results.forEach(({ status, value, reason }) => {
if (status === "fulfilled") {
console.log(`โœ… ${value.id}: ${value.value}`);
} else {
console.log(`โŒ ${reason.message}`);
}
});
}

process();
โค5๐Ÿ‘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 double = x => x * 2;
const addTen = x => x + 10;
const square = x => x * x;
const negate = x => -x;

const transform1 = compose(negate, square, addTen, double);
const transform2 = pipe(negate, square, addTen, double);

console.log(transform1(3));
console.log(transform2(3));
โค5๐Ÿ‘2๐Ÿ”ฅ1
What is the output?
Anonymous Quiz
24%
-256 -256
50%
-256 38
19%
256 -256
7%
-256 32
๐Ÿค”2๐Ÿ‘1๐Ÿ”ฅ1
CHALLENGE


const setA = new Set([1, 2, 3, 4, 5]);
const setB = new Set([3, 4, 5, 6, 7]);

const union = new Set([...setA, ...setB]);

const intersection = new Set([...setA].filter(x => setB.has(x)));

const differenceAB = new Set([...setA].filter(x => !setB.has(x)));

const symmetricDiff = new Set(
[...setA, ...setB].filter(x => !(setA.has(x) && setB.has(x)))
);

console.log([...union].join(','));
console.log([...intersection].join(','));
console.log([...differenceAB].join(','));
console.log([...symmetricDiff].join(','));
๐Ÿ”ฅ5โค2๐Ÿ‘1
๐Ÿ˜ฎ Vite+ Beta: A Web Dev Toolchain Behind One Command

Vite+ is the Vite teamโ€™s โ€˜unified toolchainโ€™ that brings Vite, Vitest, Oxlint, and similar tools together under a single vp command, whether for running a dev server, tests, formatting, or bundling.

VoidZero

๐Ÿ’ก Vite+ was originally intended to be a commercial project to fund work on Vite and related projects, but was open sourced under the MIT license earlier this year.
Please open Telegram to view this post
VIEW IN TELEGRAM
โค6๐Ÿ‘4๐Ÿ”ฅ2
CHALLENGE

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

const double = x => x * 2;
const addTen = x => x + 10;
const square = x => x ** 2;
const negate = x => -x;

const transform1 = compose(negate, square, addTen, double);
const transform2 = pipe(negate, square, addTen, double);

console.log(transform1(3));
console.log(transform2(3));
๐Ÿ”ฅ3โค2๐Ÿคฉ1
What is the output?
Anonymous Quiz
21%
-1024 38
44%
-256 28
29%
-256 38
6%
-256 38
๐Ÿ‘3โค1๐Ÿคฉ1๐Ÿคฃ1
๐Ÿ˜ƒ Wordgard: A New Rich Text Editor Library from ProseMirror's Creator

With Eloquent JavaScript and ProseMirror under his belt, not many people know more about JavaScript and making good editor controls than Marijn. Modular, supports collaborative editing, and thoughtfully built. Live demo and how to get started.

Marijn Haverbeke
Please open Telegram to view this post
VIEW IN TELEGRAM
โค7๐Ÿ”ฅ3
๐ŸคŸ Node.js 26.4 Adds Package Maps

A minor release whose headline feature is the (experimental) implementation of package maps (which let Node resolve packages from a static JSON file rather than walking node_modules). Matteo Collinaโ€™s node:vfs subsystem also begins to make an appearance.

Antoine du Hamel
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘6โค3๐Ÿ”ฅ1
CHALLENGE

class Pipeline {
#value;
#steps = [];

constructor(value) {
this.#value = value;
}

map(fn) {
this.#steps.push({ type: 'map', fn });
return this;
}

filter(fn) {
this.#steps.push({ type: 'filter', fn });
return this;
}

execute() {
return this.#steps.reduce((acc, step) => {
if (step.type === 'map') return acc.map(step.fn);
if (step.type === 'filter') return acc.filter(step.fn);
return acc;
}, this.#value);
}
}

const result = new Pipeline([1, 2, 3, 4, 5, 6])
.filter(x => x % 2 === 0)
.map(x => x ** 2)
.filter(x => x > 10)
.map(x => x - 1)
.execute();

console.log(result);
๐Ÿ‘5โค2๐Ÿ”ฅ1
โค1๐Ÿ”ฅ1
๐Ÿค– Eve: A Next.js-Style Framework for Building Agents

A new framework from Vercel that provides Next.js-esque structure for building AI-powered agents using TypeScript and Markdown. It's quite Vercel-flavored by default, but I found you can run it entirely independently of Vercel with a few settings tweaks and your own keys. Project homepage.

Vercel
Please open Telegram to view this post
VIEW IN TELEGRAM
โค4๐Ÿ”ฅ2
CHALLENGE

console.log('start');

setTimeout(() => console.log('timeout 1'), 0);

Promise.resolve()
.then(() => {
console.log('promise 1');
setTimeout(() => console.log('timeout 2'), 0);
})
.then(() => console.log('promise 2'));

setTimeout(() => console.log('timeout 3'), 0);

queueMicrotask(() => console.log('microtask'));

console.log('end');
โค5๐Ÿ”ฅ3๐Ÿ‘2
CHALLENGE


const curry = (fn) => {
const arity = fn.length;
return function curried(...args) {
if (args.length >= arity) {
return fn(...args);
}
return (...moreArgs) => curried(...args, ...moreArgs);
};
};

const volume = (l, w, h) => l * w * h;
const curriedVolume = curry(volume);

const withLength5 = curriedVolume(5);
const withLength5Width3 = withLength5(3);

console.log(typeof withLength5);
console.log(typeof withLength5Width3);
console.log(withLength5Width3(2));
console.log(curriedVolume(5)(3)(2) === withLength5(3)(2));
โค4๐Ÿ”ฅ3๐Ÿ‘1
CHALLENGE

const obj = {
name: "Quantum",
regular: function () {
return this.name;
},
arrow: () => {
return this?.name;
},
nested: function () {
const inner = () => this.name;
return inner();
},
};

console.log(obj.regular());
console.log(obj.arrow());
console.log(obj.nested());
โค4๐Ÿ‘4๐Ÿ”ฅ4
CHALLENGE

const flags = {
READ: 0b0001,
WRITE: 0b0010,
EXECUTE: 0b0100,
DELETE: 0b1000,
};

const userPermissions = flags.READ | flags.WRITE | flags.EXECUTE;
const adminPermissions = userPermissions | flags.DELETE;

const canDelete = (adminPermissions & flags.DELETE) !== 0;
const readOnly = userPermissions & ~flags.WRITE;

const toggled = userPermissions ^ flags.EXECUTE;
const shifted = (flags.DELETE << 2) | (flags.READ >> 0);

console.log(canDelete, readOnly, toggled, shifted);
โค3๐Ÿ‘2๐Ÿ”ฅ1