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
What is the output?
Anonymous Quiz
39%
Starting... Promise { 'Data loaded' } Data loaded Cleanup Processing complete
27%
Starting... Promise { <pending> } Cleanup Processing complete
18%
Starting... Promise { <pending> } Data loaded Cleanup Processing complete
15%
Starting... Data loaded Cleanup Processing complete
β€4π₯2π1π€1
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
What is the output?
Anonymous Quiz
22%
undefined 'undefined' 'number'
38%
undefined 'function' 'number'
18%
ReferenceError: innerVar is not defined
23%
42 'function' 'number'
β€3π₯3π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
What is the output?
Anonymous Quiz
54%
Hello, Taylor!
20%
TypeError: Cannot read properties of undefined (reading 'name')
18%
TypeError: this.greet is not a function
8%
undefined
β€7
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
What is the output?
Anonymous Quiz
16%
undefined
39%
2 + function increment() { count += 1; return count; }
15%
4
30%
3
β€3π3π€£2π€1
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
What is the output?
Anonymous Quiz
22%
{ map: false, weakMap: false }
31%
ReferenceError: objKey is not defined
24%
{ map: true, weakMap: false }
23%
{ map: true, weakMap: true }
β€5π1π₯1
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
β€5
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