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
CHALLENGE


class Session {
#id;
constructor(id) {
this.#id = id;
}
getId() { return this.#id; }
}

const activeSessions = new WeakSet();

const s1 = new Session("user_42");
const s2 = new Session("user_99");
let s3 = new Session("user_07");

activeSessions.add(s1);
activeSessions.add(s2);
activeSessions.add(s3);

console.log(activeSessions.has(s1)); // line A
console.log(activeSessions.has(s3)); // line B

s3 = null;

console.log(activeSessions.has(s3)); // line C

activeSessions.delete(s2);
console.log(activeSessions.has(s2)); // line D
console.log(activeSessions.size); // line E
โค7๐Ÿ‘2๐Ÿ”ฅ1
โšก๏ธ Beautiful Mermaid 1.0

Render Mermaid diagram markup to SVG or ASCII/Unicode outputs (above) from JavaScript.
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ”ฅ9โค7๐Ÿ‘2
CHALLENGE



const inventory = {
apples: 5,
bananas: 0,
cherries: 12,
dates: undefined,
elderberries: null,
};

const summary = Object.entries(inventory)
.filter(([_, value]) => value)
.reduce((acc, [key, value]) => {
acc[key] = value * 2;
return acc;
}, {});

console.log(Object.keys(summary).length);
console.log(Object.values(summary).every(v => v > 10));
console.log(Object.keys(inventory).length === Object.keys(summary).length);
๐Ÿ”ฅ3โค1๐Ÿ‘1
โค5๐Ÿ‘1๐Ÿคฉ1
๐Ÿซถ Play with a complete Windows 3.11 environment in your browser. A lot of fun! There's a recreation of 90s search engine Altavista (above), a version of mIRC that connects to an actual IRC server, and a variety of classic games.
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘9๐Ÿ”ฅ6โค2
CHALLENGE


const user = {
profile: {
getName: () => "Marcus",
getAge: () => 30,
},
settings: null,
};

const name = user.profile?.getName?.();
const age = user.profile?.getAge?.();
const theme = user.settings?.getTheme?.() ?? "dark";
const lang = user.address?.getLocale?.() ?? "en-US";

console.log(`${name} | ${age} | ${theme} | ${lang}`);
โค6๐Ÿ‘3
๐Ÿ‘€ AdonisJS v7 Released: 'Batteries-Included' Node.js Framework

A popular webapp framework that includes auth, ORM, queues, testing, etc. in a cohesive fashion. With v7 comes an all new web site, modernizations, OpenTelemetry integration, new starter kits to rapidly build new apps, barrel file generation, and end-to-end type safety.

Harminder Virk
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘8๐Ÿ”ฅ4โค1
CHALLENGE



let x = 'global';

function testScope() {
console.log(x);

if (true) {
let x = 'block';
var y = 'function';
console.log(x);
}

console.log(x);
console.log(y);
}

testScope();
๐Ÿ”ฅ6๐Ÿ‘2โค1
๐Ÿ˜ฎ numpy-ts: A NumPy Implementation for TypeScript

NumPy is a fundamental piece of the Python scientific computing ecosystem and well-entrenched in many use cases. JavaScript has some options in this regard (e.g. TensorFlow.js), but numpy-ts is an attempt to replace the NumPy experience as closely as possible (currently at 94% API coverage). Thereโ€™s an online playground if you want to give it a quick spin.

Nicolas Dupont
Please open Telegram to view this post
VIEW IN TELEGRAM
โค12๐Ÿ”ฅ5๐Ÿ‘3
๐ŸคŸ 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