CHALLENGE
const handler = {
get(target, prop, receiver) {
if (prop === 'fullName') {
return `${Reflect.get(target, 'firstName', receiver)} ${Reflect.get(target, 'lastName', receiver)}`;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (typeof value !== 'string') {
return false;
}
return Reflect.set(target, prop, value.trim(), receiver);
},
has(target, prop) {
return prop.startsWith('_') ? false : Reflect.has(target, prop);
}
};
const person = new Proxy({ firstName: ' Clara', lastName: 'Oswald ', _secret: 'hidden' }, handler);
person.firstName = ' Clara';
person.lastName = ' Oswald';
console.log(person.fullName);
console.log('_secret' in person);
console.log(Reflect.ownKeys(person).length);
๐ฅ7โค4๐2๐ค2
What is the output?
Anonymous Quiz
16%
Clara Oswald false 3
50%
Clara Oswald false 3
25%
Clara Oswald false 2
9%
Clara Oswald true 3
๐ฅ4๐2โค1
CHALLENGE
const str = "JavaScript is Awesome!";
const result = str
.split(" ")
.map((word, i) => {
if (i % 2 === 0) return word.toUpperCase();
return word.toLowerCase();
})
.map((word) => [...word].reverse().join(""))
.join("-");
console.log(result);
โค8๐2๐ฅ1
What is the output?
Anonymous Quiz
19%
tpircsavaj-SI-!emosewa
53%
TPIRCSAVAJ-si-!EMOSEWA
21%
TPIRCSAVAJ-is-!EMOSEWA
6%
TPIRCSVAJ-si-EMOSEWA!
โค3๐ฅ2
CHALLENGE
const person = { name: "Carlos", scores: [10, 20, 30] };
const clone = { ...person };
clone.name = "Diana";
clone.scores.push(40);
const snapshot = Object.assign({}, person);
snapshot.name = "Elena";
snapshot.scores.push(50);
console.log(person.name);
console.log(person.scores.length);
console.log(clone.name);
console.log(clone.scores === person.scores);
๐ฅ3๐2โค1
What is the output?
Anonymous Quiz
28%
Carlos 5 Diana true
28%
Carlos 4 Diana false
35%
Carlos 3 Diana false
10%
Diana 5 Diana true
โค2๐2๐ค1
CHALLENGE
"use strict";
function createCounter() {
let count = 0;
return {
increment() { count++; },
decrement() { count--; },
getCount() { return count; },
reset: () => { count = 0; }
};
}
const counter = createCounter();
counter.increment();
counter.increment();
counter.increment();
counter.decrement();
const { getCount, reset } = counter;
console.log(getCount());
reset();
console.log(counter.getCount());
๐ฅ8โค1
What is the output?
Anonymous Quiz
43%
2 0
27%
2 undefined
27%
TypeError: getCount is not a function
4%
3 3
CHALLENGE
const p1 = new Promise((resolve) => {
console.log("A");
resolve("X");
});
const p2 = p1.then((val) => {
console.log("B");
return val + "Y";
});
const p3 = p2.then((val) => {
console.log("C:", val);
});
console.log("D");
๐3โค2๐ฅ2
โค6๐5๐ฅ1๐ค1
CHALLENGE
class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.name = this.constructor.name;
this.statusCode = statusCode;
}
}
class ValidationError extends AppError {
constructor(message) {
super(message, 400);
this.fields = [];
}
}
function riskyOperation(value) {
if (value === null) throw new ValidationError("Null value");
if (value < 0) throw new AppError("Negative value", 422);
return value * 2;
}
const results = [];
for (const val of [10, null, -5, 3]) {
try {
results.push(riskyOperation(val));
} catch (e) {
if (e instanceof ValidationError) {
results.push(`Validation:${e.statusCode}`);
} else if (e instanceof AppError) {
results.push(`App:${e.statusCode}`);
} else {
results.push("Unknown");
}
}
}
console.log(results.join(" | "));
๐2๐คฉ2๐ฅ1
What is the output?
Anonymous Quiz
17%
20 | Unknown | App:422 | 6
63%
20 | Validation:400 | App:422 | 6
12%
20 | App:400 | App:422 | 6
9%
20 | Validation:400 | Validation:422 | 6
โค3๐ฅ2
JavaScriptโs date/time handling is notoriously messy and libraries like Moment.js became popular as a way to work around it. In 2017, Maggie Johnson-Pint, a maintainer of Moment.js, proposed the Temporal API to fix date/time handling for good, and weโre mostly there (support is growing, with Safari and Node to catch up).
Jason Williams (Bloomberg)
Please open Telegram to view this post
VIEW IN TELEGRAM
โค3
CHALLENGE
const p1 = new Promise((resolve) => {
console.log("A");
resolve("B");
});
const p2 = p1.then((val) => {
console.log(val);
return "C";
});
p2.then((val) => {
console.log(val);
});
console.log("D");
๐2๐ฅ2โค1
โค3
Please open Telegram to view this post
VIEW IN TELEGRAM
๐คฃ5โค2๐ค1
CHALLENGE
function Vehicle(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
this.describe = function () {
return `${this.year} ${this.make} ${this.model}`;
};
}
Vehicle.prototype.age = function (currentYear) {
return currentYear - this.year;
};
const car = new Vehicle("Toyota", "Supra", 1998);
const bike = new Vehicle("Harley", "Sportster", 2005);
console.log(car.describe());
console.log(bike.age(2025));
console.log(car.constructor === Vehicle);
console.log(Object.getPrototypeOf(car) === Vehicle.prototype);
๐2
What is the output?
Anonymous Quiz
14%
1998 Toyota Supra 27 false true
53%
1998 Toyota Supra 20 true true
21%
1998 Toyota Supra 20 true false
12%
Toyota Supra 1998 27 true true
โค3๐2๐ฅ2
Please open Telegram to view this post
VIEW IN TELEGRAM
โค7๐ค2