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());
β€7π€2
What is the output?
Anonymous Quiz
23%
{ map: false, weakMap: false }
32%
ReferenceError: objKey is not defined
23%
{ 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
What is the output?
Anonymous Quiz
51%
2
28%
1
12%
ReferenceError: users is not defined
10%
TypeError: activeUsers.has is not a function
π₯1
A vanilla JS library for making on-page tours and contextual help systems. Itβs been around for several years, but is still maintained, and there are lots of examples to check out β itβs really smooth.
Kamran Ahmed
Please open Telegram to view this post
VIEW IN TELEGRAM
π3β€2π₯2
CHALLENGE
function mystery() {
try {
console.log('A');
throw new Error('Oops');
console.log('B');
} catch (err) {
console.log('C');
return 'D';
} finally {
console.log('E');
return 'F';
}
console.log('G');
return 'H';
}
console.log(mystery());
β€5
π€£6π3β€2π€2
The Ultimate Guide to Understanding EventLoop in Node.js
This comprehensive guide is going to take some time to cover every detail that you need to know, so grab a cup of coffee and settle in for an exciting journey to the fascinating world of Node.js. Letβs get started!
nairihar
Please open Telegram to view this post
VIEW IN TELEGRAM
β€8π2π₯2
CHALLENGE
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const addTwo = num => num + 2;
const multiplyByThree = num => num * 3;
const subtractTen = num => num - 10;
const calculate = compose(subtractTen, multiplyByThree, addTwo);
console.log(calculate(5));
β€5π₯3π1
What is the output?
Anonymous Quiz
10%
7
44%
11
37%
((5 + 2) * 3) - 10 = 11
9%
(5 + 2) * 3 - 10 = 11
β€4π€3π2
From Chrome 137 you can try out CSS inline conditionals with the if() function. if() enables a cleaner developer interface for dynamic styles like style queries and media queries, with some key differences, which you can learn about in this post.
Please open Telegram to view this post
VIEW IN TELEGRAM
β€10π3π₯2
CHALLENGE
function Vehicle(wheels) {
this.wheels = wheels;
}
Vehicle.prototype.getWheels = function() {
return this.wheels;
};
function Car() {
Vehicle.call(this, 4);
this.doors = 4;
}
Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.constructor = Car;
const myCar = new Car();
console.log(myCar.getWheels(), myCar instanceof Vehicle);
β€4
What is the output?
Anonymous Quiz
20%
4 false
46%
4 true
29%
TypeError: myCar.getWheels is not a function
6%
undefined true
β€4π₯3π€3π1
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5π₯3π2
CHALLENGE
function getOrder() {
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => {
console.log('3');
Promise.resolve().then(() => console.log('4'));
});
Promise.resolve().then(() => console.log('5'));
console.log('6');
}
getOrder();
β€3
π7β€4π₯3
The Oxidation Compiler is creating a collection of high-performance tools for JavaScript and TypeScript.
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5π€2π1π₯1