What is the output?
Anonymous Quiz
26%
[2, 'Not found', 2, 'Not found']
34%
[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
Please open Telegram to view this post
VIEW IN TELEGRAM
๐4โค1๐ฅ1
CHALLENGE
let obj1 = { id: 1 };
let obj2 = { id: 2 };
let obj3 = { id: 3 };
const weakSet = new WeakSet([obj1, obj2]);
weakSet.add(obj3);
weakSet.delete(obj1);
obj2 = null;
const remainingObjects = [...weakSet];
console.log(remainingObjects);
๐2๐ฅ1
What is the output?
Anonymous Quiz
35%
[{ id: 3 }]
34%
TypeError: weakSet is not iterable
28%
[{ id: 2 }, { id: 3 }]
4%
[{ id: 3 }, { id: 2 }]
๐9๐ฅ5โค1
CHALLENGE
const secretData = { password: 'abc123' };
const mySet = new WeakSet();
mySet.add(secretData);
// Later in the code
delete secretData.password;
const checkAccess = (obj) => {
console.log(mySet.has(obj));
};
checkAccess(secretData);
checkAccess({ password: 'abc123' });
โค7๐2๐ฅ2
๐3๐ฅ2โค1