JavaScript
33K subscribers
1.14K photos
10 videos
33 files
814 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
🀟 Node.js EventLoop Lag + Kafka Consumer Lag: One Root Cause

The 3-Second Production Mystery That Took Me 20 Days to Solve

This is a story about how we found a 3s EventLoop lag (p99) in one of our microservices while exploring the Kafka consumer lag… and how I tracked it down and fixed.

It’s Feb 6. I notice an increase in Kafka lag in our Grafana chart...

nairihar
Please open Telegram to view this post
VIEW IN TELEGRAM
❀5πŸ‘5πŸ”₯4
CHALLENGE

const name = "Zara";
const age = 28;
const role = "engineer";

const user = { name, age, role };

const { name: fullName, age: years, role: position = "developer" } = user;

const greet = ({ name, age }) => `${name} is ${age}`;

const team = [
{ name: "Zara", age: 28 },
{ name: "Leo", age: 34 },
];

const [{ name: first }, { age: secondAge }] = team;

console.log(`${fullName}, ${years}, ${position} | ${first}, ${secondAge}`);
❀6πŸ‘4πŸ”₯2
Please open Telegram to view this post
VIEW IN TELEGRAM
❀6πŸ”₯6πŸ‘1
CHALLENGE



const a = 10n ** 3n;
const b = BigInt(Number.MAX_SAFE_INTEGER) + 1n;
const c = b - BigInt(Number.MAX_SAFE_INTEGER);

const results = {
power: a,
safe: c,
type: typeof a,
equal: 10n == 10,
strict: 10n === 10,
};

console.log(
results.power,
results.safe,
results.type,
results.equal,
results.strict
);
❀3πŸ‘2πŸ”₯1
🌟 Bun v1.3.10 Released: A Surprisingly Big Update

Bun’s REPL has been completely rewritten with many improvements (both practical and cosmetic), there's a --compile --target=browser option for building self-contained HTML files with all JS, CSS, and assets included (ideal for simple JS-powered single page apps), full support for TC39 stage 3 ES decorators, a faster event loop, barrel import optimization, and more.

Jarred Sumner
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘4πŸ”₯4❀3🀩1
CHALLENGE

class Registry {
static #cache = new Map();
static #instanceCount = 0;
static defaultTTL;

static {
Registry.#cache.set("base", { value: 42, active: true });
Registry.#instanceCount = 1;
Registry.defaultTTL = 3600;
console.log("Static block 1:", Registry.#instanceCount, Registry.defaultTTL);
}

static {
const base = Registry.#cache.get("base");
Registry.#cache.set("derived", { value: base.value * 2, active: false });
Registry.#instanceCount++;
console.log("Static block 2:", Registry.#instanceCount, Registry.#cache.size);
}

static getSnapshot() {
return [...Registry.#cache.entries()]
.map(([k, v]) => `${k}:${v.value}`)
.join(", ");
}
}

console.log("Snapshot:", Registry.getSnapshot());
console.log("TTL:", Registry.defaultTTL);
❀5πŸ‘4
πŸ˜†
Please open Telegram to view this post
VIEW IN TELEGRAM
🀣24❀3πŸ‘3πŸ”₯3
CHALLENGE

const engine = {
type: "V8",
displacement: 4.0,
getInfo() {
return `${this.type} - ${this.displacement}L`;
},
turbo: {
boost: 12,
getBoost() {
return `${this.type ?? "Unknown"} boosted at ${this.boost} psi`;
},
},
};

const detached = engine.getInfo;
const turboInfo = engine.turbo.getBoost;

console.log(engine.getInfo());
console.log(engine.turbo.getBoost());
console.log(turboInfo());
πŸ”₯5❀4
CHALLENGE

const product = {
name: "Laptop",
price: 1299,
stock: 42,
discount: 0,
category: "Electronics",
};

const filtered = Object.entries(product)
.filter(([key, value]) => Boolean(value))
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});

console.log(Object.keys(filtered).length);
console.log(Object.values(filtered).includes(0));
console.log(Object.keys(filtered).join(", "));
πŸ‘4πŸ”₯1
CHALLENGE


const transactions = [
{ id: 1, type: "credit", amount: 200 },
{ id: 2, type: "debit", amount: 50 },
{ id: 3, type: "credit", amount: 150 },
{ id: 4, type: "debit", amount: 30 },
{ id: 5, type: "credit", amount: 100 },
];

const result = transactions
.filter(tx => tx.type === "credit")
.map(tx => ({ ...tx, amount: tx.amount * 1.1 }))
.reduce((acc, tx) => acc + tx.amount, 0);

console.log(result.toFixed(2));
πŸ”₯3
What is the output?
Anonymous Quiz
23%
450.00
30%
500.00
15%
385.00
32%
495.00
❀4πŸ”₯1πŸ€”1
CHALLENGE

class AppError extends Error {
constructor(message, code) {
super(message);
this.name = "AppError";
this.code = code;
}
}

function riskyOperation(value) {
if (value === null) throw new AppError("Null value", 404);
if (typeof value !== "number") throw new TypeError("Not a number");
if (value < 0) throw new RangeError("Negative value");
return value * 2;
}

const inputs = [42, null, "hello", -5];
const results = inputs.map((input) => {
try {
return riskyOperation(input);
} catch (err) {
if (err instanceof AppError) return `AppError:${err.code}`;
if (err instanceof TypeError) return `TypeError`;
if (err instanceof RangeError) return `RangeError`;
return `UnknownError`;
}
});

console.log(results);
❀2πŸ‘2πŸ”₯1
πŸ‘€ Solid v2.0.0 Beta: The <Suspense> is Over

After a long experimental phase, Solid 2.0’s first beta lands with first-class async support where computations can return Promises or async iterables, and the reactive graph suspends and resumes around them natively. <Suspense> is retired in favor of <Loading> for initial renders, and mutations get a first-class action() primitive with optimistic support. For existing users the breaking changes are substantial, but there’s a migration guide.

Ryan Carniato
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘5❀4πŸ”₯4
CHALLENGE

const inventory = {
apples: 5,
bananas: 12,
cherries: 0,
dates: 8,
};

const result = Object.entries(inventory)
.filter(([_, qty]) => qty > 0)
.reduce((acc, [fruit, qty]) => {
acc[fruit] = qty * 2;
return acc;
}, {});

const keys = Object.keys(result);
const values = Object.values(result);

console.log(keys.length, values.reduce((sum, v) => sum + v, 0));
πŸ‘5❀2πŸ”₯2
What is the output?
Anonymous Quiz
21%
4 50
27%
3 60
19%
4 60
33%
3 50
100πŸ‘5❀1