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
896

Showing posts older than #2537 · Back to latest

Older Posts 20 shown
Post #2534 5.22K
  • ❤ 4
  • 🔥 3
Post #2533 4.87K
CHALLENGE

class Counter {
constructor(max) {
this.max = max;
}

*[Symbol.iterator]() {
let current = 0;
while (current < this.max) {
yield current++;
}
}
}

const counter = new Counter(3);
const result = [...counter, ...counter];
console.log(result);
  • ❤ 6
Post #2531 4.96K
✌️ How V8 is Making JSON.stringify More Than Twice as Fast

The V8 team has made JSON.stringify over twice as fast, giving your apps an automatic performance boost for common tasks like API responses and caching, at least once Node upgrades to V8 13.8 (Node 24 uses V8 13.6). This article unpacks the low-level work behind the speedup.

Patrick Thier (V8)
  • ❤ 10
  • 🔥 4
  • 👍 2
Post #2529 4.79K
CHALLENGE

const target = { name: 'Sarah', age: 25 };

const handler = {
get(obj, prop) {
if (prop in obj) {
return obj[prop];
}
return `Property '${prop}' not found`;
},
set(obj, prop, value) {
obj[prop] = value.toString().toUpperCase();
return true;
}
};

const proxy = new Proxy(target, handler);
proxy.city = 'boston';
console.log(proxy.name);
console.log(proxy.city);
console.log(proxy.country);
  • ❤ 5
  • 🔥 2
Post #2528 4.51K
  • 🔥 3
  • ❤ 2
  • 👍 1
Post #2527 4.84K
CHALLENGE

class Logger {
constructor(prefix) {
this.prefix = prefix;
}
log(message) {
console.log(`${this.prefix}: ${message}`);
}
}

class Database {
constructor(logger) {
this.logger = logger;
}
save(data) {
this.logger.log(`Saving ${data}`);
return `${data}_saved`;
}
}

const logger = new Logger('DB');
const db = new Database(logger);
const result = db.save('user');
console.log(result);
  • ❤ 8
  • 👍 2
Post #2526 4.49K
  • 🔥 5
  • ❤ 3
  • 👍 3
Post #2525 4.5K
CHALLENGE

const Flyable = {
fly() { return `${this.name} is flying`; }
};

const Swimmable = {
swim() { return `${this.name} is swimming`; }
};

function createDuck(name) {
return Object.assign({ name }, Flyable, Swimmable);
}

const duck = createDuck('Quackers');
console.log(duck.fly());
console.log(duck.swim());
console.log(Object.getOwnPropertyNames(duck));
  • ❤ 6
Post #2523 5.1K
  • ❤ 5
  • 👍 2
  • 🔥 2
Post #2522 4.69K
CHALLENGE

const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);

const addPrefix = str => `prefix_${str}`;
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
const addSuffix = str => `${str}_suffix`;

const process = compose(addSuffix, capitalize, addPrefix);

console.log(process('data'));
  • ❤ 4
Post #2520 5.1K
  • ❤ 6
  • 👍 4
  • 🔥 3
Post #2519 4.97K
CHALLENGE

class VideoCall {
constructor() {
this.pc = { iceConnectionState: 'new' };
this.streams = [];
}

async connect() {
this.pc.iceConnectionState = 'checking';
await Promise.resolve();
this.pc.iceConnectionState = 'connected';
this.streams.push('remote-video');
return this.pc.iceConnectionState;
}

handleConnectionChange() {
const states = ['new', 'checking', 'connected'];
return states.map(state => {
return this.pc.iceConnectionState === state ? `Status: ${state}` : null;
}).filter(Boolean);
}
}

const call = new VideoCall();
call.connect().then(() => {
console.log(call.handleConnectionChange());
});
  • ❤ 8
Post #2518 4.43K
  • ❤ 3
  • 👍 2
  • 🔥 2
Post #2517 4.45K
CHALLENGE

class ChatServer {
constructor() {
this.clients = new Set();
this.messageLog = [];
}

connect(client) {
this.clients.add(client);
return () => this.clients.delete(client);
}

broadcast(message, sender) {
this.messageLog.push(message);
this.clients.forEach(client => {
if (client !== sender) {
client.receive(message);
}
});
}
}

const server = new ChatServer();
const david = { name: 'David', receive: msg => console.log(`David got: ${msg}`) };
const sarah = { name: 'Sarah', receive: msg => console.log(`Sarah got: ${msg}`) };
const emma = { name: 'Emma', receive: msg => console.log(`Emma got: ${msg}`) };

const disconnectDavid = server.connect(david);
server.connect(sarah);
server.connect(emma);
server.broadcast('Hello everyone!', david);
disconnectDavid();
server.broadcast('Is David still here?', sarah);

console.log(server.clients.size);
  • ❤ 4
  • 👍 2
Post #2516 4.07K
✌️ The Many, Many, Many JavaScript Runtimes of the Last Decade

A meaty article (which took a year to put together) covering the myriad of JavaScript runtimes and engines both past and present, from obvious picks like Node.js to cloud platforms and lesser known ‘honorable mentions’. This is a great summary to round out your JS ecosystem knowledge.

Whatever, Jamie
  • 👍 6
  • ❤ 5
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 →