โœ•
โœ๏ธ Content byMd. Rakibul Islam
๐ŸŽฏ
MCQ
Multiple Choice ยท 100 questions
1Hardclosuresโฑ 60s

What is the output of this code?

โ–ผ
javascript
const foo = () => {
  let x = 1;
  return () => ++x;
};
const bar = foo();
console.log(bar(), bar());
2Hardevent loopโฑ 90s

What is the correct microtask/macrotask execution order?

โ–ผ
javascript
setTimeout(() => console.log('A'), 0);
queueMicrotask(() => console.log('B'));
Promise.resolve().then(() => console.log('C'));
queueMicrotask(() => console.log('D'));
console.log('E');
3HardV8 internalsโฑ 90s

What V8 optimization is broken by this code, and what is the fix?

โ–ผ
javascript
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 construction
4Hardmetaprogrammingโฑ 90s

What is the output of this code involving Proxy and Symbol?

โ–ผ
javascript
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}`);
5Hardoptimizationโฑ 90s

What does this code demonstrate about JavaScript's tail call optimization?

โ–ผ
javascript
'use strict';
function factorial(n, acc = 1) {
  if (n <= 1) return acc;
  return factorial(n - 1, n * acc); // tail call
}
console.log(factorial(100000));
6Harddata structuresโฑ 60s

What is the difference between structuredClone() and JSON.parse(JSON.stringify()) for deep cloning?

โ–ผ
7Hardasync/awaitโฑ 90s

What is the output and why?

โ–ผ
javascript
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));
8HardJavaScript ecosystemโฑ 60s

In the Temporal proposal (or date-fns/Luxon), what fundamental problem with the JavaScript Date object are they solving?

โ–ผ
9Harddesign patternsโฑ 60s

What pattern does this code implement, and what is the risk?

โ–ผ
javascript
// db.js
let instance = null;
class Database {
  constructor() {
    if (instance) return instance;
    this.connection = createConnection();
    instance = this;
  }
}
export const db = new Database();
10Hardmemory managementโฑ 60s

What is the purpose of WeakRef and FinalizationRegistry, introduced in ES2021?

โ–ผ
11Hardarchitectureโฑ 60s

What is Module Federation's key architectural advantage in a micro-frontend system compared to a monolithic SPA bundle?

โ–ผ
12HardV8 internalsโฑ 90s

What is the output of this code demonstrating V8's inline caching behavior with polymorphic function calls?

โ–ผ
javascript
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);
}
13Hardmemory managementโฑ 90s

What is the output of this code demonstrating a subtle memory leak from closures retained in a long-lived event bus?

โ–ผ
javascript
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));
}
14HardNode.js internalsโฑ 75s

What does the Node.js libuv thread pool primarily handle, given that JavaScript itself is single-threaded?

โ–ผ
15Hardconcurrency modelsโฑ 80s

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?

โ–ผ
16HardV8 internalsโฑ 90s

What is the output of this code demonstrating V8's optimization/deoptimization cycle with polymorphic argument types?

โ–ผ
javascript
function add(a, b) { return a + b; }
for (let i = 0; i < 10000; i++) add(1, 2);
add('1', 2);
17Hardarchitectureโฑ 70s

What architectural trade-off does adopting a micro-frontend architecture typically introduce, compared to a single monolithic frontend?

โ–ผ
18Hardconcurrency modelsโฑ 85s

What is the output of this code demonstrating a concurrency bug caused by shared mutable state across `Promise.all()`-driven parallel operations?

โ–ผ
javascript
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();
19Hardperformance at scaleโฑ 80s

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?

โ–ผ
20HardJS engine internalsโฑ 85s

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

Javascript MCQ Interview Questions โ€” All Levels | UyTech