JavaScript
31.9K subscribers
1.01K photos
9 videos
33 files
693 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
πŸ‘ PGlite: Run Postgres in WebAssembly

PGlite packages a WASM build of Postgres into a TypeScript library that can be run directly from Node.js (or Bun, Deno, and even the browser) and it’s only a few megabytes in size.

ElectricSQL / Neon
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘5❀2πŸ”₯2
CHALLENGE

function outer() {
let x = 10;

function inner() {
console.log(x);

if(true) {
let x = 20;
console.log(x);
}

console.log(x);
}

inner();
}

outer();
πŸ‘7❀1
πŸ‘11❀3πŸ”₯1
πŸ”Ž Node Modules Inspector

A tool that runs pnpm inside your browser, β€œinstalls” a package, then analyzes its dependencies. This can be useful for analyzing packages you already use, but also for simplifying your own projects, as 11ty’s Zach Leatherman did here.

Anthony Fu
Please open Telegram to view this post
VIEW IN TELEGRAM
❀10πŸ‘6πŸ”₯1
CHALLENGE

const ws = new WeakSet();
const obj1 = { id: 1 };
const obj2 = { id: 2 };

ws.add(obj1);
ws.add(obj2);
ws.delete(obj1);

const obj3 = { id: 2 };

console.log([
ws.has(obj2),
ws.has(obj1),
ws.has(obj3),
ws.has({ id: 2 })
]);
πŸ‘8πŸ”₯2
πŸ‘8πŸ”₯3❀2πŸ€”2🀣1
⭐ A fantastic introduction to latency in IO devices (above) over on the PlanetScale blog, complete with very useful interactive diagrams built in JavaScript.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀4πŸ‘2πŸ”₯2
CHALLENGE

class Task {
constructor(name) {
this.name = name;
}
async execute() {
const result = await Promise.resolve(this.name);
return { result };
}
}

const task = new Task('test');
task.execute().then(console.log);
πŸ”₯7πŸ‘2
πŸ‘8❀4πŸ”₯2
🀨 A Perplexing JavaScript Parsing Puzzle

It looks deceptively simple – just 14 characters of JavaScript – but after working with JavaScript for 29 years, I got it wrong. A clue: it goes back to a browser-related quirk from 30 years ago..

Hillel Wayne
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘3❀2πŸ”₯1
CHALLENGE

const users = [
{ id: 1, name: 'Alice', age: 25 },
{ id: 2, name: 'Bob', age: 30 },
{ id: 3, name: 'Charlie', age: 35 }
];

const result = users
.filter(user => user.age > 25)
.map(user => user.name.toUpperCase())
.reduce((acc, name) => acc + name[0], '');

console.log(result);
πŸ‘3πŸ”₯2❀1
πŸ‘15🀣12πŸ”₯5❀2πŸ€”2
πŸ˜†
Please open Telegram to view this post
VIEW IN TELEGRAM
🀣109πŸ‘9❀2
CHALLENGE

async function getData() {
return Promise.resolve(1);
}

async function process() {
try {
const x = await getData();
const y = await Promise.resolve(x + 1);
console.log(y + await Promise.resolve(1));
} catch(err) {
console.log('Error');
}
}

process();
πŸ‘5❀3πŸ”₯1πŸ€”1🀣1
What is the output?
Anonymous Quiz
49%
3
24%
[object Promise]
18%
2
8%
undefined
🀣9πŸ€”5❀2
CHALLENGE

const cache = new WeakMap();
const obj1 = { id: 1 };
const obj2 = { id: 2 };

cache.set(obj1, 'data1');
cache.set(obj2, 'data2');

obj2.newProp = 'test';

console.log(cache.has(obj1), cache.has(obj2), cache.has({ id: 1 }));
πŸ‘3
πŸ‘11🀣5❀2πŸ”₯1
Please open Telegram to view this post
VIEW IN TELEGRAM
❀13πŸ”₯4πŸ‘2
CHALLENGE

const counter = {
count: 0,
increment() {
this.count++;
return this.count;
}
};

const inc = counter.increment;
const boundInc = counter.increment.bind(counter);

console.log([
counter.increment(),
inc(),
boundInc(),
counter.count
]);
πŸ‘8❀1
πŸ‘10❀1πŸ”₯1