What is the output of this code?
const foo = () => {
let x = 1;
return () => ++x;
};
const bar = foo();
console.log(bar(), bar());What is the output of this code?
const foo = () => {
let x = 1;
return () => ++x;
};
const bar = foo();
console.log(bar(), bar());What is the correct microtask/macrotask execution order?
setTimeout(() => console.log('A'), 0);
queueMicrotask(() => console.log('B'));
Promise.resolve().then(() => console.log('C'));
queueMicrotask(() => console.log('D'));
console.log('E');What V8 optimization is broken by this code, and what is the fix?
function Point(x, y) {
this.x = x;
this.y = y;
}
const p1 = new Point(1, 2);
const p2 = new Point(3, 4);
p2.z = 5; // added after constructionWhat is the output of this code involving Proxy and Symbol?
const obj = new Proxy({}, {
get(target, key, receiver) {
if (key === Symbol.toPrimitive) {
return (hint) => hint === 'number' ? 42 : 'obj';
}
return Reflect.get(target, key, receiver);
}
});
console.log(+obj);
console.log(`${obj}`);What does this code demonstrate about JavaScript's tail call optimization?
'use strict';
function factorial(n, acc = 1) {
if (n <= 1) return acc;
return factorial(n - 1, n * acc); // tail call
}
console.log(factorial(100000));What is the difference between structuredClone() and JSON.parse(JSON.stringify()) for deep cloning?
What is the output and why?
async function* asyncGenerator() {
yield 1;
yield 2;
throw new Error('oops');
yield 3;
}
(async () => {
for await (const value of asyncGenerator()) {
console.log(value);
}
})().catch(e => console.log('caught:', e.message));In the Temporal proposal (or date-fns/Luxon), what fundamental problem with the JavaScript Date object are they solving?
What pattern does this code implement, and what is the risk?
// db.js
let instance = null;
class Database {
constructor() {
if (instance) return instance;
this.connection = createConnection();
instance = this;
}
}
export const db = new Database();What is the purpose of WeakRef and FinalizationRegistry, introduced in ES2021?
What is Module Federation's key architectural advantage in a micro-frontend system compared to a monolithic SPA bundle?
What is the output of this code demonstrating V8's inline caching behavior with polymorphic function calls?
function getX(obj) { return obj.x; }
const a = { x: 1 };
const b = { x: 2, y: 3 };
for (let i = 0; i < 100000; i++) {
getX(i % 2 === 0 ? a : b);
}What is the output of this code demonstrating a subtle memory leak from closures retained in a long-lived event bus?
class EventBus {
#handlers = [];
on(fn) { this.#handlers.push(fn); }
}
const bus = new EventBus();
function attachComponent(largeData) {
bus.on(() => console.log(largeData.length));
}
for (let i = 0; i < 1000; i++) {
attachComponent(new Array(100000).fill(i));
}What does the Node.js libuv thread pool primarily handle, given that JavaScript itself is single-threaded?
What is the output of this code demonstrating the risk of unbounded concurrency when using Promise.all() with a large array of async I/O operations?
What is the output of this code demonstrating V8's optimization/deoptimization cycle with polymorphic argument types?
function add(a, b) { return a + b; }
for (let i = 0; i < 10000; i++) add(1, 2);
add('1', 2);What architectural trade-off does adopting a micro-frontend architecture typically introduce, compared to a single monolithic frontend?
What is the output of this code demonstrating a concurrency bug caused by shared mutable state across `Promise.all()`-driven parallel operations?
let counter = 0;
async function increment() {
const current = counter;
await new Promise(r => setTimeout(r, 10));
counter = current + 1;
}
async function main() {
await Promise.all([increment(), increment(), increment()]);
console.log(counter);
}
main();What is the primary benefit of using `Array.prototype.reduce()` with a Map or object accumulator over repeated `.find()`/`.filter()` calls for large datasets, from a performance-at-scale perspective?
What does the V8 'Scavenger' (minor GC) specifically operate on, as part of V8's generational garbage collection strategy?
Showing 1โ20 of 100 questions