What is the key difference between Map and WeakMap in JavaScript?
What does a generator function return when called?
function* count() {
yield 1;
yield 2;
yield 3;
}
const gen = count();
console.log(gen.next());What is the output of this code using Symbol?
const s1 = Symbol('id');
const s2 = Symbol('id');
console.log(s1 === s2);
console.log(typeof s1);What does Object.freeze() guarantee?
const obj = Object.freeze({ a: 1, b: { c: 2 } });
obj.a = 99; // ?
obj.b.c = 99; // ?
console.log(obj.a, obj.b.c);What is the difference between CommonJS (require) and ES Modules (import)?
What is the output of this Proxy code?
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);Which approach causes a memory leak in a long-running JavaScript application?
What does Promise.allSettled() return when given [Promise.resolve(1), Promise.reject('err'), Promise.resolve(3)]?
What is tree-shaking in modern JavaScript bundlers?
What is the output of this async/await code?
async function fetchData() {
return 42;
}
async function main() {
const result = fetchData();
console.log(result);
console.log(await result);
}
main();What design pattern does this code implement?
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));
}
}What is the output of this code demonstrating debouncing?
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();What is the difference between debouncing and throttling?
What is the output of this code demonstrating the module pattern with closures for encapsulation?
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));What is a common cause of Cross-Site Request Forgery (CSRF) vulnerabilities, and a common mitigation?
What is the output of this code demonstrating the difference between `this` in a regular function vs arrow function inside a class method?
class Timer {
seconds = 0;
start() {
setInterval(function() {
this.seconds++;
console.log(this.seconds);
}, 1000);
}
}
new Timer().start();What is the output of this code demonstrating the Factory design pattern?
function createUser(type) {
if (type === 'admin') return { role: 'admin', permissions: ['all'] };
return { role: 'user', permissions: ['read'] };
}
const u1 = createUser('admin');
console.log(u1.permissions);What causes this code to leak memory over time in a long-running app?
const cache = [];
function addListener(el) {
const largeData = new Array(1000000).fill('x');
el.addEventListener('click', () => {
console.log(largeData.length);
});
cache.push(el);
}What is the output of this code demonstrating the difference between microtasks queued by async/await vs Promise.then()?
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');What is the primary risk of using `eval()` or `innerHTML` with unsanitized user input?
Showing 1โ20 of 100 questions