JavaScript
31.1K subscribers
1.22K photos
10 videos
33 files
894 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
What is the output?
Anonymous Quiz
38%
13 6 15
32%
11 6 15
21%
23 6 15
9%
13 6 21
👍4
TermDOM: Build Terminal UIs with HTML, CSS and the DOM

Like the look of Ink but don't like React? TermDOM implements a DOM, cascade and layout engine that paints to the terminal, so you can write a TUI with HTML and CSS. Pure JS, no native or WASM dependencies, and the official TodoMVC runs with only a stylesheet swap. Early days, but I like the idea!

Brian Kim
Please open Telegram to view this post
VIEW IN TELEGRAM
5👍3🤔2
CHALLENGE

const log = [];
Promise.resolve(1)
.then(v => { log.push('a'+v); return v+1; })
.then(v => { throw new Error('e'+v); })
.catch(e => { log.push(e.message); return 10; })
.then(v => { log.push('b'+v); });

Promise.resolve()
.then(() => log.push('c'))
.then(() => log.push('d'));

setTimeout(() => console.log(log.join(',')), 0);
🔥71
👍1
😮 DeepSeek Harness: DeepSeek's New Node-Powered Agent Harness

Today, the popular Chinese model lab unveiled its own Claude Code-alike and already racked up 30k stars. It's not a typical CLI harness, though, but runs through a web UI. Curiously, everything is a plugin, built atop Cordis, an existing Node plugin system whose author DeepSeek has hired. GitHub repo.

DeepSeek
Please open Telegram to view this post
VIEW IN TELEGRAM
👍52🔥1🤔1
CHALLENGE

function Person(name) {
if (!(this instanceof Person)) {
return new Person(name);
}
this.name = name;
}

Person.prototype.greet = function () {
return `Hi ${this.name}`;
};

function Widget(id) {
this.id = id;
return { id: id * 2 };
}

Widget.prototype.getId = function () {
return this.id;
};

const p1 = Person('Zed');
const p2 = new Person('Nova');
const w = new Widget(5);

console.log(p1.greet(), p2.greet(), w.id, w.getId);
3👍1
CHALLENGE

class EventBus {
#listeners = new Map();
on(event, fn) {
if (!this.#listeners.has(event)) this.#listeners.set(event, new Set());
this.#listeners.get(event).add(fn);
return () => this.#listeners.get(event).delete(fn);
}
emit(event, payload) {
this.#listeners.get(event)?.forEach(fn => fn(payload));
}
}
const bus = new EventBus();
const log = [];
const unsub = bus.on('data', v => log.push(`A:${v}`));
bus.on('data', v => log.push(`B:${v}`));
bus.emit('data', 1);
unsub();
bus.on('data', v => log.push(`C:${v}`));
bus.emit('data', 2);
console.log(log.join(','));
2👍1
CHALLENGE

function makeCounters() {
const counters = [];
for (var i = 0; i < 3; i++) {
let j = i;
counters.push(() => `${i}-${j}`);
}
return counters;
}
const [a, b, c] = makeCounters();
console.log(a(), b(), c());
export {};
4👍1🔥1
CHALLENGE

const a = Math.max();
const b = Math.min();
const c = 0.1 + 0.2 === 0.3;
const d = Math.max(1, NaN, 3);
const e = [1, 2, 3].reduce((sum, n) => sum + n, 0) / 3;
const f = Number.isInteger(5.0);
console.log(a, b, c, d, e, f);
👍2
CHALLENGE

const arr = [1, [2, 3], { a: 4 }];
const copy = [...arr];
copy[1].push(99);
copy[2].a = 100;
arr[0] = 999;

console.log(arr[0], arr[1], arr[2].a, copy[0]);
👍2🔥1
CHALLENGE

function makeFns() {
const result = [];
for (var i = 0; i < 3; i++) {
let j = i;
result.push(() => i + j);
}
return result;
}
const fns = makeFns();
console.log(fns.map(f => f()).join(','));
5🔥1
What is the output?
Anonymous Quiz
28%
3,4,5
32%
3,3,3
30%
0,2,4
11%
0,1,2
4👍1
CHALLENGE

class Base {}
class Derived extends Base {
static [Symbol.hasInstance](instance) {
return false;
}
}
const d = new Derived();
console.log(d instanceof Derived, d instanceof Base, Object.getPrototypeOf(Derived) === Base);
👍3🔥21
CHALLENGE

function* inner() {
yield 1;
yield 2;
return 'inner-done';
}

function* outer() {
const result = yield* inner();
yield result;
yield 3;
}

const gen = outer();
const results = [];
let r = gen.next();
while (!r.done) {
results.push(r.value);
r = gen.next();
}
console.log(results.join(','));

export {};
5👍2🔥1