TGViewer
Channel Public Channel
JavaScript

JavaScript

@javascript

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
Subscribers
31.1K
Photos
1.2K
Videos
10
Links
894

Showing posts older than #3488 · Back to latest

Older Posts 20 shown
Post #3487 2.13K
🔥 The Depths of JavaScript: Minesweeper in 247 Bytes

An analysis of a playable 8x8 Minesweeper implementation in one line of JavaScript, complete with flags and cascading blank cells. The author's 658-byte version is impressive enough, but this post covers the tricks to make it 62% smaller than that!

yui and DNEK
  • 🔥 7
  • ❤ 2
Post #3485 2.04K
CHALLENGE

function createCounters() {
const counters = [];
for (let i = 0; i < 3; i++) {
let count = 0;
counters.push(() => {
count += i;
return count;
});
}
return counters;
}

const counters = createCounters();
const first = counters.map(fn => fn()).join(',');
const second = counters.map(fn => fn()).join(',');
console.log(first, second);
  • ❤ 2
  • 🔥 1
Post #3484 2.06K
👀 htmx 4.0 has landed, the first major release in two years, with lots of changes. It remains a neat way to add interactivity to server-rendered pages without reaching for a frontend framework.
  • ❤ 3
Post #3483 2.21K
  • ❤ 1
  • 🤔 1
Post #3482 2.08K
CHALLENGE

class Timer {
#ticks = 0;
tick = () => {
this.#ticks++;
return this.#ticks;
};
reset() {
this.#ticks = 0;
return this.#ticks;
}
}

const t = new Timer();
const { tick, reset } = t;
let result;
try {
result = reset();
} catch (e) {
result = e.constructor.name;
}
console.log(tick(), tick(), result);
  • ❤ 2
  • 👍 2
Post #3481 1.81K
⛽️ 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
  • 👍 4
  • ❤ 2
Post #3480 1.89K
  • ❤ 4
  • 🔥 3
  • 👍 1
Post #3479 1.8K
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
Post #3478 1.87K
🌦 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
  • ❤ 5
  • 🔥 5
  • 👍 2
Post #3476 1.92K
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
Post #3474 1.85K
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
Post #3472 2K
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
Post #3470 1.98K
CHALLENGE

const nums = [40, 100, 1, 5, 25, 10];
nums.sort();
console.log(nums.join(' '));
  • ❤ 3
  • 🤣 3
Post #3469 2.23K
  • 🔥 3
  • 👍 1
Post #3468 2.03K
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
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →