TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2461 4.63K
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({}));
  • ❤ 5
  • 👍 1
More from @javascript
  1. Oct 4, 2026Post #3536
  2. Oct 4, 2026CHALLENGE const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); co…
  3. Oct 3, 2026🤩 The Grand Unifying Architecture of Frontend SolidJS's creator argues that HTMX, React,…
  4. Oct 2, 2026😮 How Anthropic Made Claude's Apps 3x Faster in Two Weeks A grab bag of performance lesso…
  5. Oct 2, 2026Post #3532
  6. Oct 2, 2026CHALLENGE const arr = [1, 2, 3]; const log = []; const result = arr.map((x, i) => { if (i…
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 →