What is the output?
Anonymous Quiz
46%
yellow red green yellow red
22%
yellow red green red yellow
14%
red green yellow red green
18%
green yellow red green yellow
β€8π1
Please open Telegram to view this post
VIEW IN TELEGRAM
π€£61π₯4β€2π2
CHALLENGE
async function processValues() {
try {
console.log('Start');
const a = await Promise.resolve('First');
console.log(a);
const b = await Promise.reject('Error');
console.log(b);
return 'Done';
} catch (err) {
console.log(err);
return 'Recovered';
} finally {
console.log('Finally');
}
}
processValues().then(result => console.log(result));
β€1
What is the output?
Anonymous Quiz
30%
Start First Error Finally Recovered
24%
Start First Finally Recovered
39%
Start First Error Recovered Finally
7%
Start First Finally Error Recovered
π4β€1π₯1
CHALLENGE
function greet(name) {
return `Hello, ${name}!`;
}
function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
return result + str + (values[i] ? `<em>${values[i]}</em>` : '');
}, '');
}
const user = 'Sarah';
const status = 'online';
console.log(highlight`User ${user} is currently ${status}.`);
π₯2β€1
What is the output?
Anonymous Quiz
19%
User <em>Sarah</em> is currently online.
43%
User <em>Sarah</em> is currently <em>online</em>.
15%
`User ${user} is currently ${status}.`
22%
User Sarah is currently online.
β€2π2π₯2
A meaty article (which took a year to put together) covering the myriad of JavaScript runtimes and engines both past and present, from obvious picks like Node.js to cloud platforms and lesser known βhonorable mentionsβ. This is a great summary to round out your JS ecosystem knowledge.
Whatever, Jamie
Please open Telegram to view this post
VIEW IN TELEGRAM
π6β€5
CHALLENGE
class ChatServer {
constructor() {
this.clients = new Set();
this.messageLog = [];
}
connect(client) {
this.clients.add(client);
return () => this.clients.delete(client);
}
broadcast(message, sender) {
this.messageLog.push(message);
this.clients.forEach(client => {
if (client !== sender) {
client.receive(message);
}
});
}
}
const server = new ChatServer();
const david = { name: 'David', receive: msg => console.log(`David got: ${msg}`) };
const sarah = { name: 'Sarah', receive: msg => console.log(`Sarah got: ${msg}`) };
const emma = { name: 'Emma', receive: msg => console.log(`Emma got: ${msg}`) };
const disconnectDavid = server.connect(david);
server.connect(sarah);
server.connect(emma);
server.broadcast('Hello everyone!', david);
disconnectDavid();
server.broadcast('Is David still here?', sarah);
console.log(server.clients.size);
β€2π2
β€3π2π₯2
CHALLENGE
class VideoCall {
constructor() {
this.pc = { iceConnectionState: 'new' };
this.streams = [];
}
async connect() {
this.pc.iceConnectionState = 'checking';
await Promise.resolve();
this.pc.iceConnectionState = 'connected';
this.streams.push('remote-video');
return this.pc.iceConnectionState;
}
handleConnectionChange() {
const states = ['new', 'checking', 'connected'];
return states.map(state => {
return this.pc.iceConnectionState === state ? `Status: ${state}` : null;
}).filter(Boolean);
}
}
const call = new VideoCall();
call.connect().then(() => {
console.log(call.handleConnectionChange());
});
β€6
What is the output?
Anonymous Quiz
28%
['Status: connected', 'Status: checking', 'Status: new']
14%
[]
38%
['Status: new', 'Status: checking', 'Status: connected']
20%
['Status: connected']
β€6π4π₯3
Wrapping around an (included) Swift-powered binary, this captures Mac system audio output and emits it as PCM encoded chunks at regular intervals. GitHub repo.
Nick Payne
Please open Telegram to view this post
VIEW IN TELEGRAM
β€4π2π₯1
CHALLENGE
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const addPrefix = str => `prefix_${str}`;
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);
const addSuffix = str => `${str}_suffix`;
const process = compose(addSuffix, capitalize, addPrefix);
console.log(process('data'));
β€3
What is the output?
Anonymous Quiz
35%
prefix_Data_suffix
31%
prefix_data_suffix
17%
data_suffix
18%
Prefix_data_suffix
β€5π2π₯2
Please open Telegram to view this post
VIEW IN TELEGRAM
1β€1π₯1
CHALLENGE
const Flyable = {
fly() { return `${this.name} is flying`; }
};
const Swimmable = {
swim() { return `${this.name} is swimming`; }
};
function createDuck(name) {
return Object.assign({ name }, Flyable, Swimmable);
}
const duck = createDuck('Quackers');
console.log(duck.fly());
console.log(duck.swim());
console.log(Object.getOwnPropertyNames(duck));
β€3
What is the output?
Anonymous Quiz
21%
undefined is flying undefined is swimming [ 'name', 'fly', 'swim' ]
48%
Quackers is flying Quackers is swimming [ 'name', 'fly', 'swim' ]
21%
Quackers is flying Quackers is swimming [ 'fly', 'swim', 'name' ]
10%
Quackers is flying Quackers is swimming [ 'name' ]
π₯5β€3π3
CHALLENGE
class Logger {
constructor(prefix) {
this.prefix = prefix;
}
log(message) {
console.log(`${this.prefix}: ${message}`);
}
}
class Database {
constructor(logger) {
this.logger = logger;
}
save(data) {
this.logger.log(`Saving ${data}`);
return `${data}_saved`;
}
}
const logger = new Logger('DB');
const db = new Database(logger);
const result = db.save('user');
console.log(result);
1β€8π2
What is the output?
Anonymous Quiz
20%
user_saved DB: Saving user
53%
DB: Saving user user_saved
18%
DB: Saving user user
10%
Saving user user_saved
π₯3β€2π1
CHALLENGE
const target = { name: 'Sarah', age: 25 };
const handler = {
get(obj, prop) {
if (prop in obj) {
return obj[prop];
}
return `Property '${prop}' not found`;
},
set(obj, prop, value) {
obj[prop] = value.toString().toUpperCase();
return true;
}
};
const proxy = new Proxy(target, handler);
proxy.city = 'boston';
console.log(proxy.name);
console.log(proxy.city);
console.log(proxy.country);
β€4π₯2