CHALLENGE
const p1 = new Promise((resolve) => {
console.log("A");
resolve("X");
});
const p2 = p1.then((val) => {
console.log("B");
return val + "Y";
});
const p3 = p2.then((val) => {
console.log("C:", val);
});
console.log("D");
π3β€2π₯2
β€6π5π₯1π€1
CHALLENGE
class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.name = this.constructor.name;
this.statusCode = statusCode;
}
}
class ValidationError extends AppError {
constructor(message) {
super(message, 400);
this.fields = [];
}
}
function riskyOperation(value) {
if (value === null) throw new ValidationError("Null value");
if (value < 0) throw new AppError("Negative value", 422);
return value * 2;
}
const results = [];
for (const val of [10, null, -5, 3]) {
try {
results.push(riskyOperation(val));
} catch (e) {
if (e instanceof ValidationError) {
results.push(`Validation:${e.statusCode}`);
} else if (e instanceof AppError) {
results.push(`App:${e.statusCode}`);
} else {
results.push("Unknown");
}
}
}
console.log(results.join(" | "));
π2π€©2π₯1
What is the output?
Anonymous Quiz
17%
20 | Unknown | App:422 | 6
62%
20 | Validation:400 | App:422 | 6
12%
20 | App:400 | App:422 | 6
9%
20 | Validation:400 | Validation:422 | 6
β€3π₯2
JavaScriptβs date/time handling is notoriously messy and libraries like Moment.js became popular as a way to work around it. In 2017, Maggie Johnson-Pint, a maintainer of Moment.js, proposed the Temporal API to fix date/time handling for good, and weβre mostly there (support is growing, with Safari and Node to catch up).
Jason Williams (Bloomberg)
Please open Telegram to view this post
VIEW IN TELEGRAM
β€3
CHALLENGE
const p1 = new Promise((resolve) => {
console.log("A");
resolve("B");
});
const p2 = p1.then((val) => {
console.log(val);
return "C";
});
p2.then((val) => {
console.log(val);
});
console.log("D");
π₯2β€1π1
β€3
Please open Telegram to view this post
VIEW IN TELEGRAM
π€£5β€2π€1
CHALLENGE
function Vehicle(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
this.describe = function () {
return `${this.year} ${this.make} ${this.model}`;
};
}
Vehicle.prototype.age = function (currentYear) {
return currentYear - this.year;
};
const car = new Vehicle("Toyota", "Supra", 1998);
const bike = new Vehicle("Harley", "Sportster", 2005);
console.log(car.describe());
console.log(bike.age(2025));
console.log(car.constructor === Vehicle);
console.log(Object.getPrototypeOf(car) === Vehicle.prototype);
π2
What is the output?
Anonymous Quiz
14%
1998 Toyota Supra 27 false true
54%
1998 Toyota Supra 20 true true
21%
1998 Toyota Supra 20 true false
11%
Toyota Supra 1998 27 true true
β€3π2π₯2
Please open Telegram to view this post
VIEW IN TELEGRAM
β€7π€2
CHALLENGE
class EventEmitter {
#listeners = new WeakMap();
#registry = new FinalizationRegistry((label) => {
console.log(`Cleaned up: ${label}`);
});
subscribe(target, callback) {
if (!this.#listeners.has(target)) {
this.#listeners.set(target, []);
}
this.#listeners.get(target).push(callback);
this.#registry.register(target, target.name ?? "unknown");
}
emit(target) {
const cbs = this.#listeners.get(target);
if (cbs) cbs.forEach(cb => cb());
}
}
const emitter = new EventEmitter();
let obj1 = { name: "sensor" };
let obj2 = { name: "timer" };
const ws = new WeakSet([obj1, obj2]);
emitter.subscribe(obj1, () => console.log("sensor fired"));
emitter.subscribe(obj2, () => console.log("timer fired"));
emitter.subscribe(obj1, () => console.log("sensor logged"));
emitter.emit(obj1);
console.log(ws.has(obj1));
obj1 = null;
console.log(ws.has({ name: "sensor" }));π₯2β€1
What is the output?
Anonymous Quiz
23%
sensor fired sensor logged true false
35%
sensor fired sensor logged false false
35%
sensor fired timer fired sensor logged true false
6%
sensor fired sensor logged true true
β€3π1
The Node.js team has long been discussing shifting Node to a new schedule of one major release per year (instead of two), removing the odd/even distinction, and making every release LTS (with a prior 11 months of alpha/current status). This is a preview post not intended for final publication till April, so things are subject to change (backup version).
The Node.js Team
Please open Telegram to view this post
VIEW IN TELEGRAM
β€1