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

What is the key difference between Map and WeakMap in JavaScript?

โ–ผ
2Mediumgeneratorsโฑ 45s

What does a generator function return when called?

โ–ผ
javascript
function* count() {
  yield 1;
  yield 2;
  yield 3;
}
const gen = count();
console.log(gen.next());
3MediumSymbolโฑ 40s

What is the output of this code using Symbol?

โ–ผ
javascript
const s1 = Symbol('id');
const s2 = Symbol('id');
console.log(s1 === s2);
console.log(typeof s1);
4Mediumobjectsโฑ 45s

What does Object.freeze() guarantee?

โ–ผ
javascript
const obj = Object.freeze({ a: 1, b: { c: 2 } });
obj.a = 99;        // ?
obj.b.c = 99;      // ?
console.log(obj.a, obj.b.c);
5Mediummodulesโฑ 40s

What is the difference between CommonJS (require) and ES Modules (import)?

โ–ผ
6HardProxyโฑ 60s

What is the output of this Proxy code?

โ–ผ
javascript
const handler = {
  get(target, key) {
    return key in target ? target[key] : `No property: ${key}`;
  }
};
const obj = new Proxy({ name: 'Dev' }, handler);
console.log(obj.name);
console.log(obj.age);
7Mediummemory managementโฑ 40s

Which approach causes a memory leak in a long-running JavaScript application?

โ–ผ
8Mediumpromisesโฑ 45s

What does Promise.allSettled() return when given [Promise.resolve(1), Promise.reject('err'), Promise.resolve(3)]?

โ–ผ
9Mediumbuild toolsโฑ 30s

What is tree-shaking in modern JavaScript bundlers?

โ–ผ
10Hardasync/awaitโฑ 60s

What is the output of this async/await code?

โ–ผ
javascript
async function fetchData() {
  return 42;
}
async function main() {
  const result = fetchData();
  console.log(result);
  console.log(await result);
}
main();
11Mediumdesign patternsโฑ 45s

What design pattern does this code implement?

โ–ผ
javascript
class EventEmitter {
  constructor() { this.listeners = {}; }
  on(event, cb) {
    (this.listeners[event] = this.listeners[event] || []).push(cb);
  }
  emit(event, data) {
    (this.listeners[event] || []).forEach(cb => cb(data));
  }
}
12Mediumperformance optimizationโฑ 50s

What is the output of this code demonstrating debouncing?

โ–ผ
javascript
function debounce(fn, delay) {
  let timer;
  return function(...args) {
    clearTimeout(timer);
    timer = setTimeout(() => fn.apply(this, args), delay);
  };
}
const log = debounce(() => console.log('called'), 100);
log(); log(); log();
13Mediumperformance optimizationโฑ 45s

What is the difference between debouncing and throttling?

โ–ผ
14Mediummodulesโฑ 50s

What is the output of this code demonstrating the module pattern with closures for encapsulation?

โ–ผ
javascript
const bankAccount = (() => {
  let balance = 100;
  return {
    withdraw(amount) {
      if (amount > balance) return 'Insufficient funds';
      balance -= amount;
      return balance;
    }
  };
})();
console.log(bankAccount.balance);
console.log(bankAccount.withdraw(30));
15Mediumsecurity basicsโฑ 50s

What is a common cause of Cross-Site Request Forgery (CSRF) vulnerabilities, and a common mitigation?

โ–ผ
16Mediumthis bindingโฑ 60s

What is the output of this code demonstrating the difference between `this` in a regular function vs arrow function inside a class method?

โ–ผ
javascript
class Timer {
  seconds = 0;
  start() {
    setInterval(function() {
      this.seconds++;
      console.log(this.seconds);
    }, 1000);
  }
}
new Timer().start();
17Mediumdesign patternsโฑ 40s

What is the output of this code demonstrating the Factory design pattern?

โ–ผ
javascript
function createUser(type) {
  if (type === 'admin') return { role: 'admin', permissions: ['all'] };
  return { role: 'user', permissions: ['read'] };
}
const u1 = createUser('admin');
console.log(u1.permissions);
18Mediummemory managementโฑ 55s

What causes this code to leak memory over time in a long-running app?

โ–ผ
javascript
const cache = [];
function addListener(el) {
  const largeData = new Array(1000000).fill('x');
  el.addEventListener('click', () => {
    console.log(largeData.length);
  });
  cache.push(el);
}
19Hardasync/awaitโฑ 70s

What is the output of this code demonstrating the difference between microtasks queued by async/await vs Promise.then()?

โ–ผ
javascript
async function a() {
  console.log('a start');
  await b();
  console.log('a end');
}
async function b() {
  console.log('b');
}
console.log('script start');
a();
console.log('script end');
20Mediumsecurity basicsโฑ 40s

What is the primary risk of using `eval()` or `innerHTML` with unsanitized user input?

โ–ผ

Showing 1โ€“20 of 100 questions

Javascript MCQ Interview Questions โ€” All Levels | UyTech