TGViewer
JavaScript test JavaScript test @js_test · 9.77K subscribers
Post #6515 286
❗️Что будет на выходе:

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 });

Ответ: Computing result... Cache hit! Computing result...

JavaScript test | #JavaScript & Max
More from @js_test
  1. Sep 21, 2026❓Что будет на выходе? 'use strict'; function strictModeExample() { undeclaredVariable = 10…
  2. Sep 20, 2026❗️Что будет на выходе? async function test() { console.log('1'); setTimeout(() => { consol…
  3. Sep 20, 2026❗️Что будет на выходе? const user = { profile: { name: 'Alice', settings: { notifications:…
  4. Sep 20, 2026❗️Что будет на выходе? function* range(start, end) { while (start < end) { yield start++;…
  5. Sep 19, 2026❗️Что будет на выходе: const arr = [3, 8, 12]; const even = (elem) => elem % 2 === 0; cons…
  6. Sep 19, 2026❓Что будет на выходе? const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(..…
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 →