❤4
Draft diagrams quickly with TypeScript. Define your data models through top-level type aliases and interfaces and it automatically lays out the nodes in an efficient way. GitHub repo.
Andrei Neculaesei
Please open Telegram to view this post
VIEW IN TELEGRAM
❤8👍1
CHALLENGE
const data = '{"users": [{"name": "Sarah", "age": 25}, {"name": "Mike", "age": null}]}';
try {
const parsed = JSON.parse(data);
const result = parsed.users.map(user => {
return user.age ?? 'unknown';
});
console.log(result.join(' - '));
} catch (error) {
console.log('Parse error occurred');
}
const invalidJson = '{"name": "John", age: 30}';
try {
JSON.parse(invalidJson);
console.log('Success');
} catch {
console.log('Invalid');
}❤9
What is the output?
Anonymous Quiz
28%
Parse error occurred, Invalid
35%
25 - null, Success
10%
25 - unknown
27%
25 - unknown, Invalid
👍7🤔2❤1
CHALLENGE
class Logger {
log(msg) {
return `[LOG]: ${msg}`;
}
}
class Formatter {
format(text) {
return text.toUpperCase();
}
}
class Service {
constructor(logger, formatter) {
this.logger = logger;
this.formatter = formatter;
}
process(data) {
const formatted = this.formatter.format(data);
return this.logger.log(formatted);
}
}
const service = new Service(new Logger(), new Formatter());
console.log(service.process('hello world'));❤3👍2🤔1
What is the output?
Anonymous Quiz
49%
[LOG]: HELLO WORLD
28%
HELLO WORLD
14%
hello world
9%
[LOG]: hello world
CHALLENGE
let obj1 = { name: 'Sarah' };
let obj2 = { name: 'Mike' };
obj1.ref = obj2;
obj2.ref = obj1;
let weakRef = new WeakRef(obj1);
let registry = new FinalizationRegistry((value) => {
console.log(`Cleanup: ${value}`);
});
registry.register(obj1, 'obj1-cleaned');
obj1 = null;
obj2 = null;
console.log(weakRef.deref()?.name || 'undefined');
console.log('Script completed');What is the output?
Anonymous Quiz
30%
Sarah Script completed
43%
undefined Script completed Cleanup: obj1-cleaned
20%
Sarah Script completed Cleanup: obj1-cleaned
7%
undefined Script completed
🔥4🤔3❤1
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;
}
}
const emitter = new EventEmitter();
emitter.on('test', x => console.log(x * 2))
.on('test', x => console.log(x + 5))
.emit('test', 10);❤5
Back in May 1995, a 33 year old Brendan Eich built the first prototype of JavaScript in just ten days, originally codenamed Mocha (and then LiveScript). On December 4, 1995, Netscape and Sun Microsystems officially announced 'JavaScript' in a press release as "an easy-to-use object scripting language designed for creating live online applications that link together objects and resources on both clients and servers."
Over thirty years, JavaScript has cemented its place at the heart of the Web platform, and more broadly in desktop apps, operating systems (e.g. Windows' use of React Native), mobile apps, and even on microcontrollers.
Please open Telegram to view this post
VIEW IN TELEGRAM
❤12👍4🤔1
CHALLENGE
const map = new Map([
['a', 1],
['b', 2],
['c', 3]
]);
const key = { id: 'key' };
map.set(key, 4);
map.set(key, 5);
const result = [];
result.push(map.get('a'));
result.push(map.get(key));
result.push(map.size);
result.push(map.has({ id: 'key' }));
console.log(result);
What is the output?
Anonymous Quiz
27%
[1, 5, 4, true]
32%
[1, 4, 4, false]
27%
[1, 5, 4, false]
14%
[1, 5, 5, true]
❤2🔥2👍1