JavaScript Quiz (Advanced – Extreme Hard) - All Questions
This JavaScript Extreme Hard Quiz is crafted for senior and expert-level developers. It focuses on deep JavaScript internals such as execution context, closures, prototypes, event loop, memory management, async behavior, edge cases, and real-world interview scenarios.
Question 1: What creates a new execution context in JavaScript?
- Block scope
- Function invocation
- Variable declaration
- Object creation
Explanation: Each function invocation creates a new execution context.
Question 2: Which statement about closures is correct?
- They copy variables
- They capture lexical scope
- They work only with var
- They destroy memory automatically
Explanation: Closures retain access to their lexical scope.
Question 3: What is the output type of typeof null?
- null
- undefined
- object
- number
Explanation: This is a historical JavaScript bug.
Question 4: Which queue has higher priority in the event loop?
- Callback queue
- Microtask queue
- Render queue
- Macro queue
Explanation: Microtasks are executed before macrotasks.
Question 5: Which method schedules a microtask?
- setTimeout()
- setInterval()
- Promise.then()
- requestAnimationFrame()
Explanation: Promise.then() is queued in the microtask queue.
Question 6: What does Object.create(null) produce?
- Empty object
- Object without prototype
- Frozen object
- Sealed object
Explanation: It creates an object without Object.prototype.
Question 7: Which statement about arrow functions is true?
- They have their own this
- They bind arguments object
- They inherit this lexically
- They can be used as constructors
Explanation: Arrow functions inherit this from surrounding scope.
Question 8: What happens when you use new with an arrow function?
- Creates object
- Throws error
- Returns undefined
- Ignores new
Explanation: Arrow functions cannot be used as constructors.
Question 9: Which operation causes garbage collection eligibility?
- Setting variable to null
- Removing event listener
- Losing all references
- Calling delete
Explanation: Objects are collected when no references exist.
Question 10: Which keyword prevents prototype modification?
Explanation: Object.freeze() prevents modifications.
Question 11: What is the result of [] + {}?
- [object Object]
- {}
- NaN
- undefined
Explanation: Array converts to empty string, object to string.
Question 12: What is the result of {} + [] in non-strict mode?
- 0
- [object Object]
- NaN
- SyntaxError
Explanation: {} is treated as block, +[] evaluates to 0.
Question 13: Which feature enables tail-call optimization?
- Arrow functions
- Strict mode
- Recursion
- Generators
Explanation: TCO is only specified in strict mode.
Question 14: Which statement about hoisting is correct?
- let is hoisted and initialized
- const is hoisted and initialized
- var is hoisted and initialized
- let is hoisted but uninitialized
Explanation: let exists in TDZ until initialized.
Question 15: What is Temporal Dead Zone?
- Garbage memory
- Unreachable scope
- Time before initialization
- Async delay
Explanation: TDZ exists before variable initialization.
Question 16: Which operator short-circuits on null or undefined only?
Explanation: Nullish coalescing ignores falsy values like 0.
Question 17: Which method preserves property descriptors?
- Object.assign()
- Spread operator
- Object.create()
- JSON.parse()
Explanation: Object.create() allows descriptor control.
Question 18: What is the prototype of a function?
- null
- Object.prototype
- Function.prototype
- undefined
Explanation: Functions inherit from Function.prototype.
Question 19: Which API blocks the main thread?
- setTimeout()
- fetch()
- alert()
- Promise
Explanation: alert() blocks execution.
Question 20: Which structure ensures immutability?
- Map
- Set
- Object.freeze()
- WeakMap
Explanation: freeze prevents modifications.
Question 21: Which object allows weakly held keys?
Explanation: WeakMap keys are weakly referenced.
Question 22: Which value is falsy?
Explanation: NaN is falsy.
Question 23: Which method schedules rendering callback?
- setTimeout()
- Promise.then()
- requestAnimationFrame()
- queueMicrotask()
Explanation: requestAnimationFrame syncs with repaint.
Question 24: Which mechanism prevents memory leaks in DOM?
- Garbage collector
- Weak references
- Event delegation
- Strict mode
Explanation: Event delegation reduces detached listeners.
Question 25: Which object is global in Node.js?
Explanation: Node.js uses global instead of window.
Question 26: Which statement about promises is true?
- They are synchronous
- They execute immediately
- They resolve once
- They block threads
Explanation: Promises settle only once.
Question 27: Which method flattens nested arrays?
- flat()
- reduce()
- concat()
- spread
Explanation: flat() flattens nested arrays.
Question 28: Which feature enables lazy evaluation?
- Promises
- Generators
- Async functions
- Closures
Explanation: Generators pause and resume execution.
Question 29: Which syntax pauses generator execution?
Explanation: yield pauses generator execution.
Question 30: Which object converts iterable to iterator?
- Symbol.iterator
- Iterator()
- forEach()
- map()
Explanation: Symbol.iterator defines iteration behavior.
Question 31: Which operator checks prototype chain?
Explanation: instanceof checks prototype chain.
Question 32: Which operation mutates array length?
- slice()
- map()
- length = 0
- filter()
Explanation: Setting length mutates the array.
Question 33: Which API enables shared memory?
- SharedArrayBuffer
- ArrayBuffer
- Buffer
- TypedArray
Explanation: SharedArrayBuffer enables shared memory.
Question 34: Which keyword prevents variable hoisting misuse?
Explanation: let introduces block scoping.
Question 35: Which feature ensures referential transparency?
- Closures
- Pure functions
- Promises
- Callbacks
Explanation: Pure functions always return same output.
Question 36: Which API allows atomic operations?
Explanation: Atomics provide atomic operations.
Question 37: Which value is returned by Promise.resolve()?
- Resolved value
- Promise
- Callback
- Undefined
Explanation: Promise.resolve() returns a resolved Promise.
Question 38: Which structure preserves insertion order?
Explanation: Map preserves insertion order.
Question 39: Which operator prevents optional chaining errors?
Explanation: Optional chaining prevents access errors.
Question 40: Which pattern avoids callback hell?
- Event listeners
- Promises
- Loops
- Closures
Explanation: Promises flatten async chains.
Question 41: Which API handles streaming data?
- Streams
- Buffers
- Promises
- Workers
Explanation: Streams process data incrementally.
Question 42: Which method freezes nested objects automatically?
- Object.freeze()
- Deep freeze
- JSON.stringify()
- None
Explanation: freeze is shallow by default.
Question 43: Which statement about this in strict mode is correct?
- Defaults to window
- Defaults to global
- Is undefined
- Is null
Explanation: In strict mode, this is undefined.
Question 44: Which construct enables cooperative multitasking?
- Promises
- Generators
- Async/await
- Workers
Explanation: Generators yield control cooperatively.
Question 45: Which API enables true parallelism?
- setTimeout()
- Promises
- Web Workers
- Event loop
Explanation: Web Workers run in separate threads.
Question 46: Which operation forces synchronous layout?
- Reading offsetHeight
- Changing opacity
- Using transform
- Using will-change
Explanation: Reading layout properties forces reflow.