What is the output?
Anonymous Quiz
16%
['Alice', null, true, null]
45%
['Alice', undefined, true, undefined]
22%
['Alice', null, true, undefined]
17%
TypeError: Cannot read properties of null (reading 'handle')
๐7๐คฉ5
Motion is a popular and powerful animation library most commonly associated with React, but now thereโs a new Vue flavor and itโs feature complete, too.
Matt Perry (Motion)
Please open Telegram to view this post
VIEW IN TELEGRAM
๐6โค5
CHALLENGE
function Vehicle(type) {
this.type = type;
}
Vehicle.prototype.getType = function() {
return this.type;
};
function Car(make) {
this.make = make;
}
Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.constructor = Car;
const myCar = new Car('Tesla');
myCar.type = 'electric';
console.log(myCar.getType(), myCar instanceof Vehicle, myCar.constructor.name);
โค1
What is the output?
Anonymous Quiz
17%
undefined true Car
24%
electric false Vehicle
44%
electric true Car
14%
electric true undefined
๐6โค4๐ค3
CHALLENGE
const target = { a: 1, b: 2 };
const handler = {
get(obj, prop) {
return prop in obj ? obj[prop] * 2 : 'Not found';
}
};
const proxy = new Proxy(target, handler);
// Add a property to the original target
target.c = 3;
// Attempt to access properties through proxy and Reflect
console.log([
proxy.a,
proxy.z,
Reflect.get(target, 'b'),
Reflect.get(proxy, 'c')
]);
๐4
What is the output?
Anonymous Quiz
27%
[2, 'Not found', 2, 'Not found']
33%
[2, 'Not found', 2, 3]
18%
[2, undefined, 2, 6]
22%
[2, 'Not found', 2, 6]
๐8๐ค7โค3๐ฅ1
CHALLENGE
type User = {
id: number;
name: string;
role?: 'admin' | 'user';
};
function processUser(user: Partial<User>): string {
const defaultUser: User = {
id: 0,
name: 'Guest',
role: 'user'
};
const mergedUser = { ...defaultUser, ...user };
if (mergedUser.role === 'admin') {
return `Admin: ${mergedUser.name}`;
}
return `User: ${mergedUser.name} (ID: ${mergedUser.id})`;
}
console.log(processUser({ name: 'John', role: 'admin' }));
๐7โค1
What is the output?
Anonymous Quiz
22%
User: John (ID: 0)
35%
Admin: John (ID: 0)
15%
User: John
28%
Admin: John
๐ฅ6๐4โค2
CHALLENGE
function processConfig(config) {
const cache = config.cache ?? true;
const timeout = config.timeout ?? 1000;
const retries = config.retries ?? 3;
return {
useCache: cache,
timeoutMs: timeout,
maxRetries: retries
};
}
const result = processConfig({ timeout: 0, retries: false });
console.log(result);
๐3
CHALLENGE
function processInput(userInput) {
const defaultValue = 'default';
const value1 = userInput?.value ?? defaultValue;
const value2 = userInput?.value || defaultValue;
const result = {
a: 0 ?? 'zero',
b: '' ?? 'empty',
c: null ?? 'null',
d: undefined ?? 'undefined',
comparison: value1 === value2
};
console.log(result);
}
processInput({ value: '' });
๐7
What is the output?
Anonymous Quiz
28%
{ a: 'zero', b: 'empty', c: 'null', d: 'undefined', comparison: false }
32%
{ a: 'zero', b: 'empty', c: null, d: undefined, comparison: true }
18%
{ a: 0, b: '', c: 'null', d: 'undefined', comparison: true }
22%
{ a: 0, b: '', c: 'null', d: 'undefined', comparison: false }
๐7โค4๐ฅ4
CHALLENGE
class ShoppingCart {
constructor() {
if (ShoppingCart.instance) {
return ShoppingCart.instance;
}
this.items = [];
ShoppingCart.instance = this;
}
addItem(item) {
this.items.push(item);
}
getItems() {
return [...this.items];
}
}
const cart1 = new ShoppingCart();
const cart2 = new ShoppingCart();
cart1.addItem('Book');
cart2.addItem('Laptop');
console.log(cart1.getItems());
๐6
What is the output?
Anonymous Quiz
13%
['Laptop']
43%
['Book', 'Laptop']
36%
['Book']
8%
TypeError: Cannot read property 'push' of undefined
๐10๐ค4โค2๐ฅ2๐คฉ1
Airtable is a popular data table database SaaS, but hereโs a NestJS-powered open-source alternative in a similar manner that sits atop Postgres. GitHub repo.
Teable Team
Please open Telegram to view this post
VIEW IN TELEGRAM
๐4โค2๐ฅ2๐คฃ1
CHALLENGE
function Device(name) {
this.name = name;
this.isOn = false;
}
Device.prototype.turnOn = function() {
this.isOn = true;
return `${this.name} is now on`;
};
function Smartphone(name, model) {
Device.call(this, name);
this.model = model;
}
Smartphone.prototype = Object.create(Device.prototype);
Smartphone.prototype.constructor = Smartphone;
Smartphone.prototype.turnOn = function() {
const result = Device.prototype.turnOn.call(this);
return `${result} (model: ${this.model})`;
};
const myPhone = new Smartphone('iPhone', '13 Pro');
console.log(myPhone.turnOn());
๐ฅ7โค2๐2๐คฃ1
What is the output?
Anonymous Quiz
57%
iPhone is now on (model: 13 Pro)
13%
undefined
20%
iPhone is now on
10%
[object Object] is now on (model: 13 Pro)
๐ฅ5๐2โค1