JavaScript
31.2K subscribers
1.22K photos
10 videos
33 files
886 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 str = "2024-01-15";
const result = str.replace(/(\d+)-(\d+)-(\d+)/, "$3/$2/$1");
const s2 = "abc".padStart(6, "12");
const s3 = [..."hello"].reverse().join("");
console.log(result, s2, s3);
👍52🔥1
↗️ TanStack Charts: A New Chart Grammar Option

In the past few weeks, TanStack has been rapidly iterating on a new, framework-neutral way to declaratively specify a large number of chart-related visualizations in JavaScript. Output renders to SVG or canvas and can be styled as you wish. Here's a comparison against other established options.

TanStack
Please open Telegram to view this post
VIEW IN TELEGRAM
7👍2
CHALLENGE

class Money {
#amount;
constructor(amount) { this.#amount = amount; }
[Symbol.toPrimitive](hint) {
if (hint === 'number') return this.#amount;
if (hint === 'string') return `$${this.#amount}`;
return `Money(${this.#amount})`;
}
}
const m = new Money(42);
console.log(`${m}`, m + 8, m == 42);
5🤩3🔥1
🤟 Node.js 26.7.0 (Current) Released

Landing just two days after 26.6, coverage reports can now include files your tests didn't touch with --test-coverage-include-all, FFI and SQLite pick up crash fixes, and Perfetto tracing support lands, though you'll need a custom build to use it.

Antoine du Hamel
Please open Telegram to view this post
VIEW IN TELEGRAM
4👍1
CHALLENGE

const arr = [1, 2, 3, 4, 5];
arr[Symbol.iterator] = function* () {
for (let i = 0; i < 3; i++) yield arr[i] * 2;
};
console.log([...arr], JSON.stringify(arr));
1👍1🔥1
👀 anydoc: Convert 14 Document Formats into Markdown

A Rust-powered library (with Node.js and WASM bindings) that converts Word, PowerPoint, Excel, OpenDocument, RTF, EPUB, CSV, and PDF documents into Markdown. I tried it on a 1,600 page PDF and it took less than 2 seconds. There's also an in-browser demo to try it out. GitHub repo.

Firecrawl
Please open Telegram to view this post
VIEW IN TELEGRAM
👍31🔥1
CHALLENGE

function test() {
try {
console.log(y);
} catch (e) {
return e.constructor.name;
}
}

let result1 = test();
let y = 'hoisted';

console.log(result1, typeof y, y);
🔥4👍1
Did you know JavaScript supports a third type of comment (beyond // and /* */)? 😉 Mat Marquis shows off hashbang comments in a short YouTube video. And yes, they're in the language spec!
Please open Telegram to view this post
VIEW IN TELEGRAM
🤔4🔥21👍1
CHALLENGE

const obj = { a: { b: null }, getVal: null };
let counter = 0;
function sideEffect() {
counter++;
return counter;
}
const result = obj?.a?.b?.[sideEffect()] ?? 'default1';
const result2 = obj.getVal?.(sideEffect()) ?? 'default2';
const result3 = obj?.a?.c?.d ?? sideEffect();
console.log(result, result2, result3, counter);
🔥2👍1
CHALLENGE

const key = 'greet';
const name = 'world';
const obj = {
name,
[key]() { return `Hello, ${this.name}`; },
[`${key}Arrow`]: () => `Hello, ${this?.name}`,
};
console.log(`${obj.greet()} | ${obj.greetArrow()}`);
2👍2
👀 Migrating a Large Flow Monorepo to TypeScript

Over several years, Yelp moved 1.4 million lines off Flow, and this writeup is more useful as a guide to running any long migration than as a Flow story. It was a big win on its own terms, with type coverage up from 83% to 96%.

Shawn Walton (Yelp)
Please open Telegram to view this post
VIEW IN TELEGRAM
👍31
CHALLENGE

function combine(a, b = 10, ...rest) {
return JSON.stringify([a, b, rest]);
}
const inputs = [1, undefined, 3, 4, 5];
console.log(combine(...inputs));
3👍1
The js1024 code golfing contest is over and we have three winners! Skydreams, a Super Monkey Ball-like experience, came in first place. You can read the readable and minified source if you want to see the techniques used.
🔥42