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
32%
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
40%
[LOG]: HELLO WORLD [LOG]: COMPOSITION ROCKS
36%
[LOG]: COMPOSITION ROCKS [LOG]: hello world
15%
[LOG]: composition rocks [LOG]: HELLO WORLD
10%
[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
โค8๐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
โค8๐ฅ1
Created at Pixar in the 80s, the RenderMan Interface Specification was an early API for building 3D scenes. Anders has been building a Node-based, 90s-style renderer for the format โas a stroll down amnesia laneโ in pure JavaScript.
Anders Brownworth
Please open Telegram to view this post
VIEW IN TELEGRAM
๐2๐ฅ2โค1
CHALLENGE
const data = '{"name":"Sarah","age":25,"skills":["JavaScript","Python"]}'
const parsed = JSON.parse(data)
const stringified = JSON.stringify(parsed, null, 0)
const reparsed = JSON.parse(stringified)
try {
const invalid = '{name:"John","incomplete":}'
JSON.parse(invalid)
} catch (e) {
console.log(e.name)
}
console.log(typeof parsed.age)
console.log(reparsed.skills.length)
console.log(JSON.stringify({a: undefined, b: null, c: 0}))What is the output?
Anonymous Quiz
22%
SyntaxError number 2 {"b":null,"c":0}
48%
TypeError string 2 {"a":undefined,"b":null,"c":0}
25%
SyntaxError number 2 {"a":null,"b":null,"c":0}
5%
ReferenceError number 2 {"b":null,"c":0}
๐คฃ7โค3๐2
๐ฏ๐ต Fancy writing JavaScript in Japanese (above)? Say ใใใซใกใฏ to KokoScript.
๐คฃ5โค4๐1๐ฅ1
CHALLENGE
const user = { name: 'Sarah', age: 28 };
const greeting = 'Hello';
const template = `${greeting}, ${user.name}! You are ${user.age} years old.`;
function createMessage(strings, ...values) {
return strings.reduce((result, string, i) => {
return result + string + (values[i] ? `[${values[i]}]` : '');
}, '');
}
const tagged = createMessage`Welcome ${user.name}, age: ${user.age}!`;
console.log(template);
console.log(tagged);โค1
What is the output?
Anonymous Quiz
38%
Hello, Sarah! You are 28 years old. Welcome Sarah, age: 28!
30%
Hello, Sarah! You are 28 years old. Welcome [Sarah], age: [28]
29%
Hello, Sarah! You are 28 years old. Welcome [Sarah], age: [28]!
3%
Hello, undefined! You are undefined years old. Welcome [Sarah], age: [28]!
โค3๐1
Ever wondered how devtools can magically turn mangled, minified JavaScript back into readable source while debugging? Zero magic; thatโs a source map doing its job. But how do source maps actually work under the hood?
Manoj Vivek
Please open Telegram to view this post
VIEW IN TELEGRAM
โค1๐1๐ฅ1