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

What is a closure in JavaScript?

โ–ผ
javascript
function counter() {
  let count = 0;
  return function() {
    return ++count;
  };
}
const increment = counter();
console.log(increment()); // ?
console.log(increment()); // ?
2Mediumpromisesโฑ 30s

Which statement about Promises is CORRECT?

โ–ผ
3Mediumevent loopโฑ 60s

What is the output of this code?

โ–ผ
javascript
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');
4MediumES6โฑ 45s

What does the spread operator do in this code?

โ–ผ
javascript
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5];
arr1.push(99);
console.log(arr2);
5Mediumeventsโฑ 30s

What is event bubbling in JavaScript?

โ–ผ
6Mediumarraysโฑ 30s

What is the difference between map() and forEach() in JavaScript?

โ–ผ
7MediumES2020โฑ 40s

What does the optional chaining operator (?.) do?

โ–ผ
javascript
const user = { address: null };
console.log(user?.address?.city);
8Mediumpromisesโฑ 30s

What does Promise.all() do when one of the promises rejects?

โ–ผ
9Mediumdestructuringโฑ 40s

What is the output of this destructuring assignment?

โ–ผ
javascript
const { name, age = 25, role = 'dev' } = { name: 'Alice', age: 30 };
console.log(name, age, role);
10Mediumoperatorsโฑ 45s

What is the nullish coalescing operator (??) and what does it return?

โ–ผ
javascript
const a = null ?? 'default';
const b = 0 ?? 'default';
const c = '' ?? 'default';
console.log(a, b, c);
11Mediumprototypesโฑ 45s

What is prototypal inheritance in JavaScript?

โ–ผ
javascript
function Animal(name) {
  this.name = name;
}
Animal.prototype.speak = function() {
  return this.name + ' makes a noise';
};
const dog = new Animal('Rex');
console.log(dog.speak());
12Mediumclosuresโฑ 35s

What will this code output?

โ–ผ
javascript
function makeAdder(x) {
  return function(y) {
    return x + y;
  };
}
const add5 = makeAdder(5);
console.log(add5(3));
13Mediumfetch APIโฑ 30s

What does the `fetch()` API return?

โ–ผ
14Mediumarraysโฑ 40s

What is the output of this array reduce example?

โ–ผ
javascript
const nums = [1, 2, 3, 4];
const sum = nums.reduce((acc, n) => acc + n, 0);
console.log(sum);
15MediumREST APIโฑ 30s

Which HTTP method is idempotent and typically used to update an entire resource?

โ–ผ
16Mediumthis bindingโฑ 50s

What is the output of this code demonstrating the `this` keyword inside a regular method?

โ–ผ
javascript
const obj = {
  name: 'Widget',
  getName: function() {
    return this.name;
  }
};
const fn = obj.getName;
console.log(obj.getName());
console.log(fn());
17Mediumdebuggingโฑ 35s

What is the purpose of `try...catch` in JavaScript?

โ–ผ
javascript
try {
  JSON.parse('invalid json');
} catch (err) {
  console.log('Caught:', err.message);
}
18Mediumobjectsโฑ 30s

What does `Object.keys(obj)` return?

โ–ผ
javascript
const obj = { a: 1, b: 2, c: 3 };
console.log(Object.keys(obj));
19MediumOOPโฑ 50s

What is the output of this code involving a class and inheritance?

โ–ผ
javascript
class Animal {
  constructor(name) { this.name = name; }
  speak() { return `${this.name} makes a sound`; }
}
class Dog extends Animal {
  speak() { return `${super.speak()}, specifically a bark`; }
}
console.log(new Dog('Rex').speak());
20Mediumevent loopโฑ 40s

What is the event loop responsible for in JavaScript?

โ–ผ

Showing 1โ€“20 of 100 questions

Javascript MCQ Interview Questions โ€” All Levels | UyTech