CHALLENGE
function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
getValue: () => count
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue(), counter2.getValue());
counter1.decrement();
console.log(counter1.getValue(), counter2.getValue());β€5π3π€©1
β€9π₯3
CHALLENGE
const wm = new WeakMap();
const obj1 = { name: 'first' };
const obj2 = { name: 'second' };
const obj3 = obj1;
wm.set(obj1, 'value1');
wm.set(obj2, 'value2');
wm.set(obj3, 'value3');
console.log(wm.get(obj1));
console.log(wm.get(obj2));
console.log(wm.get(obj3));
console.log(wm.has(obj1));
console.log(wm.size);
β€3π2
What is the output?
Anonymous Quiz
21%
value3 value2 value3 true 3
31%
value3 value2 value3 true undefined
35%
value1 value2 value1 true undefined
13%
value1 value2 value3 true 2
π6π₯3
CHALLENGE
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}
try {
throw new CustomError('Something went wrong');
} catch (e) {
console.log(e instanceof Error);
console.log(e instanceof CustomError);
console.log(e.constructor.name);
console.log(e.name);
}π1
What is the output?
Anonymous Quiz
23%
true, false, Error, CustomError
33%
false, true, CustomError, Error
39%
true, true, CustomError, CustomError
6%
true, true, Error, Error
π6β€3π₯2
CHALLENGE
class EventEmitter {
constructor() {
this.events = {};
}
on(event, callback) {
this.events[event] = this.events[event] || [];
this.events[event].push(callback);
return this;
}
emit(event, data) {
if (this.events[event]) {
this.events[event].forEach(cb => cb(data));
}
return this;
}
}
class Logger {
log(msg) { console.log(`[LOG]: ${msg}`); }
}
class DataProcessor {
constructor(emitter, logger) {
this.emitter = emitter;
this.logger = logger;
this.emitter.on('process', (data) => {
this.logger.log(data.toUpperCase());
});
}
process(data) {
this.emitter.emit('process', data);
}
}
const emitter = new EventEmitter();
const logger = new Logger();
const processor = new DataProcessor(emitter, logger);
processor.process('hello world');
emitter.emit('process', 'composition rocks');1π4β€1
What is the output?
Anonymous Quiz
39%
[LOG]: HELLO WORLD [LOG]: COMPOSITION ROCKS
34%
[LOG]: COMPOSITION ROCKS [LOG]: hello world
17%
[LOG]: composition rocks [LOG]: HELLO WORLD
11%
[LOG]: hello world [LOG]: composition rocks
π3β€1π₯1
Did you know the Node.js project maintains a page about security best practices organized around how to mitigate ten of the most significant vectors? Topics include networking weaknesses, timing attacks, supply chain attacks, and the monkey patching of intrinsics.
Node Documentation
Please open Telegram to view this post
VIEW IN TELEGRAM
β€3π1π₯1
CHALLENGE
const obj = { count: 0 };
const arr = [obj, obj, obj];
function increment(item) {
item.count++;
return item;
}
const results = arr.map(increment);
console.log(obj.count);
console.log(results[0] === results[1]);
console.log(results.length);
console.log(arr[0].count);3β€6
β€7π3π€3
Think something like Plausible or Google Analytics, but built in Node and ready for you to host yourself. Hereβs the full feature list. MIT licensed but also available as a paid hosted service.
Umami Software, Inc.
Please open Telegram to view this post
VIEW IN TELEGRAM
β€4π₯1