CHALLENGE
const user = { id: 1, name: 'Alice' };
const userData = new WeakMap();
userData.set(user, { lastLogin: '2023-01-01' });
const clone = { ...user };
const originalData = userData.get(user);
const cloneData = userData.get(clone);
console.log(originalData, cloneData);
β€1π1
Two members of the Angular team presented a session at this weekβs Google I/O event on the latest updates to the Angular framework in anticipation of the eventual release of Angular 20 next Thursday.
Chasanoff and Thompson (Google)
Please open Telegram to view this post
VIEW IN TELEGRAM
π₯4π2
CHALLENGE
function mystery() {
try {
throw new Error('Oops');
return 'A';
} catch (err) {
return 'B';
} finally {
return 'C';
}
}
function wrapper() {
try {
return mystery();
} finally {
console.log('D');
}
}
console.log(wrapper());
π7
π₯3β€2π2
CHALLENGE
function compose(...funcs) {
return function(x) {
return funcs.reduceRight((acc, fn) => fn(acc), x);
};
}
const add10 = x => x + 10;
const multiply2 = x => x * 2;
const toString = x => `Result: ${x}`;
const composed = compose(toString, multiply2, add10);
console.log(composed(5));
π6β€1
π8π€4β€2π₯2
CHALLENGE
try {
try {
// Creating a custom error type
class CustomError extends Error {
constructor(message) {
super(message);
this.name = "CustomError";
}
}
const fn = () => {
throw new CustomError("Something went wrong");
};
try {
fn();
} catch (e) {
throw new TypeError("Type error occurred");
}
} catch (e) {
console.log(e instanceof Error, e.name, e instanceof TypeError);
}
} catch (e) {
console.log("Outer catch", e.message);
}
β€5π2π₯1
What is the output?
Anonymous Quiz
30%
true 'CustomError' false
31%
true 'TypeError' false
21%
false 'CustomError' false
18%
true 'TypeError' true
β€3π3π₯2
CHALLENGE
function* counter() {
let i = 1;
while (true) {
const reset = yield i++;
if (reset) {
i = 1;
}
}
}
const gen = counter();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next(true).value);
console.log(gen.next().value);
β€2
What is the output?
Anonymous Quiz
31%
1, 2, 1, 2
33%
1, 2, undefined, 1
20%
1, 2, 1, 1
15%
1, 2, 3, 4
π8β€2
CHALLENGE
const users = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Charlie' }
];
const userScores = new WeakMap();
// Set scores for users
userScores.set(users[0], 95);
userScores.set(users[1], 80);
// Remove reference to Bob
users[1] = null;
let sum = 0;
for (const user of users) {
if (user && userScores.has(user)) {
sum += userScores.get(user);
}
}
console.log(sum);
π7β€2
What is the output?
Anonymous Quiz
22%
Error: Invalid value used as weak map key
30%
175
36%
95
13%
undefined
β€4π₯1
Please open Telegram to view this post
VIEW IN TELEGRAM
π€11π€£8π4
CHALLENGE
class ShoppingCart {
constructor() {
if (ShoppingCart.instance) {
return ShoppingCart.instance;
}
this.items = [];
ShoppingCart.instance = this;
}
addItem(item) {
this.items.push(item);
}
getItems() {
return [...this.items];
}
}
const cart1 = new ShoppingCart();
const cart2 = new ShoppingCart();
cart1.addItem('Book');
cart2.addItem('Laptop');
console.log(cart1.getItems());
β€3
What is the output?
Anonymous Quiz
6%
[]
50%
['Book', 'Laptop']
18%
Error: Cannot read properties of undefined (reading 'push')
26%
['Book']
π7
Big news from the Remix camp this week. About a year ago, Remix and React Router merged together reflecting their shared goals and code, but now itβs all change again. React Router is now basically what Remix originally intended to be, and so βRemixβ is rebooting as a model-first, low-dependency, Web API-centric full-stack framework built on Preact. Itβll no longer be a 'React framework' per se.
Michael Jackson and Ryan Florence
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5π1π₯1
CHALLENGE
const team = {
lead: { name: 'Alice', projects: ['Alpha', 'Beta'] },
dev: { name: 'Bob', projects: ['Gamma'] },
tester: { name: 'Charlie', projects: [] }
};
const {
lead: { projects: [leadProject] },
dev: { projects: [devProject = 'Delta'] },
tester: { projects: [testerProject = 'Epsilon'] }
} = team;
console.log(`${leadProject}-${devProject}-${testerProject}`);
β€3
What is the output?
Anonymous Quiz
29%
Alpha-Gamma-Epsilon
27%
Alpha-Gamma-undefined
21%
undefined-Gamma-Epsilon
24%
Alpha-Delta-Epsilon
π6β€5π€2π€£2