CHALLENGE
function createCounter() {
let count = 0;
function increment() {
count++;
return count;
}
function decrement() {
count--;
return count;
}
return { increment, decrement, reset: () => count = 0 };
}
const counter = createCounter();
counter.increment();
counter.increment();
counter.decrement();
const { increment, reset } = counter;
increment();
reset();
increment();
console.log(counter.increment());
β€3
π₯5β€3π2
Please open Telegram to view this post
VIEW IN TELEGRAM
π€£35π8π₯5β€3
CHALLENGE
function processUserData(data) {
try {
if (!data) {
throw new Error('No data provided');
}
if (!data.name) {
throw new TypeError('Name is required');
}
return { success: true, user: data.name };
} catch (err) {
if (err instanceof TypeError) {
return { success: false, reason: 'validation-failed' };
}
return { success: false, reason: 'unknown-error' };
}
}
console.log(processUserData({}));
β€3π1
What is the output?
Anonymous Quiz
24%
TypeError: Name is required
48%
{ success: false, reason: 'validation-failed' }
19%
{ success: false, reason: 'unknown-error' }
8%
{ success: true, user: undefined }
π₯5β€3π3π€1
CHALLENGE
const cache = new WeakMap();
function expensiveOperation(obj) {
if (cache.has(obj)) {
console.log('Cache hit!');
return cache.get(obj);
}
console.log('Computing result...');
const result = obj.value * 2;
cache.set(obj, result);
return result;
}
const user = { value: 42 };
expensiveOperation(user);
expensiveOperation(user);
expensiveOperation({ value: 42 });
β€2
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
28%
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
22%
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π1
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; }
16%
4
29%
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