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
895

Showing posts older than #2657 · Back to latest

Older Posts 20 shown
Post #2656 3.99K
CHALLENGE

const sym1 = Symbol('test');
const sym2 = Symbol('test');
const obj = {
[sym1]: 'value1',
[sym2]: 'value2',
regular: 'value3'
};

const sym3 = Symbol.for('global');
const sym4 = Symbol.for('global');

console.log(sym1 === sym2);
console.log(sym3 === sym4);
console.log(Object.keys(obj).length);
console.log(Object.getOwnPropertySymbols(obj).length);
Post #2654 3.6K
  • ❤ 4
  • 🔥 2
  • 👍 1
Post #2653 3.78K
CHALLENGE

const cache = new Map();

function createHandler(id) {
const data = { id, value: new Array(1000).fill(id) };
cache.set(id, data);

return function(action) {
if (action === 'get') return data;
if (action === 'clear') cache.delete(id);
};
}

const handler1 = createHandler('user-1');
const handler2 = createHandler('user-2');

handler1('clear');
console.log(cache.size);
console.log(handler1('get').id);
Post #2652 3.8K
🤩 Fetch Streams are Great, But Not for Measuring Upload/Download Progress

Fetch upload streams seem well-suited for tracking the progress of uploads, but as Jake notes “just because stuff is taken from the stream doesn’t mean it’s yet been sent over the network”. He also touches on an issue relating to measuring download progress using response streams.

Jake Archibald
  • 🤔 6
  • 🔥 3
  • 👍 2
Post #2651 3.55K
  • 👍 6
  • ❤ 5
Post #2650 3.76K
CHALLENGE

const nums = [1, 2, 3, 4, 5];
const result = nums
.filter(n => n > 2)
.map(n => n * 2)
.reduce((acc, n) => {
acc.push(n + 1);
return acc;
}, [])
.slice(1);

console.log(result);
console.log(nums);
  • ❤ 2
Post #2649 3.76K
👀 The 'Shai-Hulud' npm Supply Chain Attack Rumbles On

Now named after a term for the sandworms of the Dune universe, the ongoing malicious supply chain attack affecting the npm ecosystem has grown in scale with hundreds of packages affected in an attempt to exfiltrate tokens and secrets from developers’ machines.

Pandya, van der Zee, and Brown (Socket)
  • ❤ 7
  • 👍 2
  • 🔥 1
Post #2648 3.59K
  • 🔥 10
Post #2647 3.67K
CHALLENGE

const moduleCache = new Map();

async function loadModule(name) {
if (moduleCache.has(name)) {
return moduleCache.get(name);
}

const module = await Promise.resolve({
default: () => `Module ${name} loaded`,
version: '1.0.0'
});

moduleCache.set(name, module);
return module;
}

const results = [];
loadModule('auth').then(m => results.push(m.default()));
loadModule('auth').then(m => results.push(m.version));
loadModule('utils').then(m => results.push(m.default()));

setTimeout(() => console.log(results.join(', ')), 0);
  • 🤔 4
  • ❤ 3
Post #2646 3.47K
🌟 Behind the Scenes of bun install" is an epic post by Lydia Hallie of the Bun project covering not only what Bun has done to make its package installation mechanism fast, but also the process and pain points of package installation more generally.

bun
  • ❤ 4
  • 🤔 3
  • 👍 2
Post #2645 3.78K
  • 👍 3
  • ❤ 2
  • 🔥 2
Post #2644 3.93K
CHALLENGE

const multiply = (a) => (b) => (c) => a * b * c;

const step1 = multiply(2);
const step2 = step1(3);
const result1 = step2(4);

const result2 = multiply(2)(3)(4);

const partialMultiply = multiply(5);
const result3 = partialMultiply(2)(3);

const doubler = multiply(2)(1);
const result4 = doubler(7);

console.log(result1, result2, result3, result4);
  • ❤ 3
Post #2643 3.88K
👀 Feedsmith 2.0: Web Feed Parsing and Generation Library

As well as parsing feeds of various types, you can also create RSS, Atom, JSON Feed, and OPML files with many common namespaces (iTunes, Podcast, Media RSS, Dublin Core, etc.) – here’s a quick start tutorial for using it both in browsers or Node. GitHub repo.

Maciej Lamberski
  • ❤ 4
  • 👍 3
  • 🔥 2
Post #2641 4.05K
CHALLENGE

class EventManager {
constructor() {
this.listeners = new Map();
}

addListener(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
}
}

const manager = new EventManager();
const obj = { name: 'Component' };
manager.addListener('click', () => console.log(obj.name));
obj = null;
console.log(manager.listeners.get('click').size);
  • ❤ 3
Post #2640 3.97K
🤟 Node.js v24.8.0 (Current) Released

The big new feature is added support for inspecting HTTP/2 network calls made from Node in Chrome DevTools. There have also been some cryptography related enhancements and npm gets upgraded to v11.6.

Michaël Zasso
  • ❤ 10
  • 👍 3
  • 🔥 1
Post #2639 4.12K
  • ❤ 4
  • 👍 3
  • 🔥 2
Post #2638 4.24K
CHALLENGE

console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
setTimeout(() => console.log('4'), 0);
console.log('5');
Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));
queueMicrotask(() => console.log('8'));
console.log('9');
  • 🔥 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 →