JavaScript
31.7K subscribers
990 photos
9 videos
33 files
678 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
✌️ jsonrepair: Repair Invalid JSON Documents

This has lots of possible use cases, including dealing with weird JSON coming back from LLMs or non-compliant JSON spat out by poorly built software. You can use it from Node, as a CLI tool, or try a basic version online.

Jos de Jong
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ”₯8❀3πŸ‘1
CHALLENGE

async function fetchData() {
return 'Data loaded';
}

async function processData() {
console.log('Starting...');
try {
const result = fetchData();
console.log(result);
console.log(await result);
return 'Processing complete';
} catch (error) {
return 'Error occurred';
} finally {
console.log('Cleanup');
}
}

processData().then(result => console.log(result));
❀3
🀩 Bruno: An IDE for Exploring and Testing HTTP APIs

An open source (though a commercial version is available) Node and Electron-based desktop app for crafting and testing HTTP requests, complex and simple. Think of it as a lightweight alternative to something like Postman.

Anoop M D, Anusree P S and Contributors
Please open Telegram to view this post
VIEW IN TELEGRAM
❀5πŸ‘3
CHALLENGE

function outer() {
console.log(innerVar);
console.log(typeof innerFunc);

var innerVar = 42;

function innerFunc() {
return innerVar;
}

let anotherVar = 100;
console.log(typeof anotherVar);
}

outer();
❀2
CHALLENGE

function* rangeGenerator(start, end, step = 1) {
let current = start;
while (current <= end) {
yield current;
current += step;
}
}

const numbers = rangeGenerator(1, 10, 2);

numbers.next();
numbers.next();

const values = [...numbers];
console.log(values);
❀2
❀4πŸ‘4πŸ”₯3
CHALLENGE

const obj = {
name: 'Taylor',
greet() {
return `Hello, ${this.name}!`;
},
delayedGreet() {
setTimeout(function() {
console.log(this.greet());
}, 100);
}
};

obj.delayedGreet();
❀4
CHALLENGE

function createCounter() {
let count = 0;

function increment() {
count += 1;
return count;
}

function decrement() {
count -= 1;
return count;
}

return { increment, decrement, value: () => count };
}

const counter = createCounter();
counter.increment();
counter.increment();
counter.decrement();

console.log(counter.value() + counter.increment());
❀4
❀3πŸ‘3🀣2πŸ€”1
🟠Vercel Acquires NuxtLabs

Vercel has acquired the company that caretakes the Nuxt project and employs some of its core team – a move Vue creator Evan You is quite optimistic about. Vercel now manages, or at least supports, several key projects like Next.js, Turborepo, Svelte, and shadcn/ui. Nuxt itself remains open source and has a promising future. Vercel’s Guillermo Rauch shares a little more about the move here.

NuxtLabs / Vercel
Please open Telegram to view this post
VIEW IN TELEGRAM
❀8πŸ‘1πŸ”₯1
CHALLENGE

const memoryLeak = () => {
const cache = new Map();
const weakCache = new WeakMap();

const objKey = { id: 123 };
const data = { name: 'User data', value: 42 };

cache.set(objKey, data);
weakCache.set(objKey, data);

// Simulate removing reference to key
const result = { map: cache.has(objKey), weakMap: weakCache.has(objKey) };
// objKey = null; // This would be an error, as const can't be reassigned

return result;
};

console.log(memoryLeak());
❀6πŸ€”2
CHALLENGE

function createCounter() {
let count = 0;

return {
increment() {
return ++count;
},
reset() {
const oldCount = count;
count = 0;
return oldCount;
}
};
}

const counterA = createCounter();
const counterB = createCounter();

counterA.increment();
counterA.increment();
counterB.increment();
const result = counterA.reset() + counterB.reset();
console.log(result);
❀3
What is the output?
Anonymous Quiz
21%
undefined
23%
NaN
47%
3
9%
2
❀5
✌️ What’s the Difference Between Ordinary Functions and Arrow Functions?

This sounds like basic stuff, but James always does a good job of digging in and explaining things in a way that gives you a more nuanced way to think about a concept, even if it’s just β€œWhich function declaration syntax should I use?”

James Sinclair
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘7❀2πŸ”₯1
CHALLENGE

const users = [
{ id: 1, name: 'Sarah' },
{ id: 2, name: 'Miguel' },
{ id: 3, name: 'Jordan' }
];

const activeUsers = new WeakSet();
activeUsers.add(users[0]);
activeUsers.add(users[2]);

users.splice(1, 1); // Remove Miguel

let count = 0;
for (const user of users) {
if (activeUsers.has(user)) count++;
}

console.log(count);
❀5πŸ”₯2