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
Imagine something like Node.js but really stripped back: bare, if you will. Like Node, itโs built on top of V8 and libuv (though it's designed to support multiple JavaScript engines) but Bareโs approach is to provide as little as possible (a module system, addon system, and thread support) and then rely upon userland modules that can evolve independently of Bare itself. Itโs an interesting idea โ more details here.
Holepunch
Please open Telegram to view this post
VIEW IN TELEGRAM
โค5๐4๐ฅ2
CHALLENGE
async function test() {
console.log('1');
setTimeout(() => {
console.log('2');
}, 0);
await Promise.resolve();
console.log('3');
new Promise(resolve => {
console.log('4');
resolve();
}).then(() => {
console.log('5');
});
console.log('6');
}
test();
console.log('7');
๐5โค2๐ฅ1
What is the output?
Anonymous Quiz
29%
1 3 4 5 6 7 2
35%
1 7 3 4 6 5 2
20%
1 7 3 4 5 6 2
15%
1 3 4 6 5 7 2
โค14๐ค6๐3
One of Denoโs compelling features is its support for Jupyter Notebooks and easy notebook-style programming, such as is common in the Python world. Trevor looks at a practical use of using such a notebook environment for data exploration.
Trevor Manz
Please open Telegram to view this post
VIEW IN TELEGRAM
โค6๐ฅ2๐คฉ2๐1
CHALLENGE
function getCity(person) {
return person?.address?.city ?? 'Unknown';
}
const data = [
null,
{ name: 'Alice' },
{ name: 'Bob', address: null },
{ name: 'Charlie', address: { street: '123 Main' } },
{ name: 'David', address: { city: 'Boston' } }
];
const cities = data.map(getCity);
console.log(cities);
๐3โค1