What is a closure in JavaScript?
function counter() {
let count = 0;
return function() {
return ++count;
};
}
const increment = counter();
console.log(increment()); // ?
console.log(increment()); // ?What is a closure in JavaScript?
function counter() {
let count = 0;
return function() {
return ++count;
};
}
const increment = counter();
console.log(increment()); // ?
console.log(increment()); // ?Which statement about Promises is CORRECT?
What is the output of this code?
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');What does the spread operator do in this code?
const arr1 = [1, 2, 3];
const arr2 = [...arr1, 4, 5];
arr1.push(99);
console.log(arr2);What is event bubbling in JavaScript?
What is the difference between map() and forEach() in JavaScript?
What does the optional chaining operator (?.) do?
const user = { address: null };
console.log(user?.address?.city);What does Promise.all() do when one of the promises rejects?
What is the output of this destructuring assignment?
const { name, age = 25, role = 'dev' } = { name: 'Alice', age: 30 };
console.log(name, age, role);What is the nullish coalescing operator (??) and what does it return?
const a = null ?? 'default';
const b = 0 ?? 'default';
const c = '' ?? 'default';
console.log(a, b, c);What is prototypal inheritance in 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());What will this code output?
function makeAdder(x) {
return function(y) {
return x + y;
};
}
const add5 = makeAdder(5);
console.log(add5(3));What does the `fetch()` API return?
What is the output of this array reduce example?
const nums = [1, 2, 3, 4];
const sum = nums.reduce((acc, n) => acc + n, 0);
console.log(sum);Which HTTP method is idempotent and typically used to update an entire resource?
What is the output of this code demonstrating the `this` keyword inside a regular method?
const obj = {
name: 'Widget',
getName: function() {
return this.name;
}
};
const fn = obj.getName;
console.log(obj.getName());
console.log(fn());What is the purpose of `try...catch` in JavaScript?
try {
JSON.parse('invalid json');
} catch (err) {
console.log('Caught:', err.message);
}What does `Object.keys(obj)` return?
const obj = { a: 1, b: 2, c: 3 };
console.log(Object.keys(obj));What is the output of this code involving a class and inheritance?
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());What is the event loop responsible for in JavaScript?
Showing 1โ20 of 100 questions