JavaScript
31.9K subscribers
1.01K photos
9 videos
33 files
691 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 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());
});
6
🤟 AudioTee.js: macOS System Audio Capture for Node.js

Wrapping around an (included) Swift-powered binary, this captures Mac system audio output and emits it as PCM encoded chunks at regular intervals. GitHub repo.

Nick Payne
Please open Telegram to view this post
VIEW IN TELEGRAM
3👍2🔥1
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'));
3
5👍2🔥2
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));
3
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);
18👍2
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);
3🔥2
✌️ 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)
Please open Telegram to view this post
VIEW IN TELEGRAM
9🔥4👍2
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);
5
3🔥3
💻 The Deno team has put together 😉 a brief video summarizing the Deno vs Oracle JavaScript trademark fight. You can also learn a bit more about it in this open letter to Oracle asking it to 'free JavaScript.'
Please open Telegram to view this post
VIEW IN TELEGRAM
4👍4🔥1
11🤣10🤔4👍2🔥1
CHALLENGE

const numbers = [1, 2, 3, 4, 5];

const result = numbers
.map(n => n * 2)
.filter(n => n > 5)
.reduce((acc, n, index) => {
acc.sum += n;
acc.indices.push(index);
return acc;
}, { sum: 0, indices: [] });

console.log(result.sum);
console.log(result.indices);
🤔103
🤔254
Sorry for the confusion earlier! The correct answer is actually 24, not 18.
After mapping and filtering, we get [6, 8, 10], and summing them gives 6 + 8 + 10 = 24.

Thanks Fabricio for the note
👍18🤣11🔥41🤩1