JavaScript Quiz (Advanced) - All Questions
This JavaScript Advanced Quiz is designed for experienced developers preparing for tough interviews. It covers closures, scope, prototypes, async behavior, event loop basics, performance, and tricky JavaScript edge cases.
Question 1: What is a closure in JavaScript?
- A function with no name
- A function bundled with its lexical scope
- A block scope variable
- A callback function
Explanation: Closures allow functions to access variables from their lexical scope.
Question 2: Which keyword creates block-scoped variables?
Explanation: let creates block-scoped variables.
Question 3: What will typeof undefined return?
- null
- undefined
- object
- string
Explanation: typeof undefined returns 'undefined'.
Question 4: Which statement about hoisting is correct?
- let is hoisted and initialized
- var is hoisted and initialized
- const is hoisted and initialized
- let is hoisted but not initialized
Explanation: let variables exist in the temporal dead zone until initialized.
Question 5: Which operator checks value and type equality?
Explanation: === checks both value and type.
Question 6: Which array method mutates the original array?
- map()
- filter()
- slice()
- splice()
Explanation: splice() modifies the original array.
Question 7: Which method returns the first element matching a condition?
- filter()
- map()
- find()
- reduce()
Explanation: find() returns the first matching element.
Question 8: What is the output of typeof NaN?
Explanation: NaN is considered a number type.
Question 9: Which keyword prevents reassignment of a variable?
Explanation: const prevents reassignment.
Question 10: Which statement stops event bubbling?
- preventDefault()
- stop()
- stopPropagation()
- cancel()
Explanation: stopPropagation() stops event bubbling.
Question 11: Which function executes after a delay once?
- setInterval()
- delay()
- setTimeout()
- wait()
Explanation: setTimeout() runs code once after delay.
Question 12: Which function repeats execution at intervals?
- setTimeout()
- repeat()
- setInterval()
- loop()
Explanation: setInterval() repeats execution.
Question 13: Which method merges two arrays?
- join()
- merge()
- concat()
- push()
Explanation: concat() merges arrays into a new one.
Question 14: Which keyword defines a class?
- object
- function
- class
- constructor
Explanation: class keyword defines a class.
Question 15: Which keyword is used for inheritance?
- super
- inherits
- extends
- prototype
Explanation: extends creates inheritance.
Question 16: Which method returns all object keys?
- Object.values()
- Object.entries()
- Object.keys()
- Object.get()
Explanation: Object.keys() returns property names.
Question 17: Which method prevents object modification?
- Object.lock()
- Object.seal()
- Object.freeze()
- const
Explanation: Object.freeze() prevents modifications.
Question 18: Which keyword refers to the parent class constructor?
- this()
- parent()
- super()
- base()
Explanation: super() calls the parent constructor.
Question 19: Which operator handles null or undefined values?
Explanation: Nullish coalescing handles null or undefined.
Question 20: Which method trims whitespace from both ends of a string?
- strip()
- clean()
- trim()
- cut()
Explanation: trim() removes leading and trailing whitespace.
Question 21: Which keyword exports a module?
Explanation: export exposes module members.
Question 22: Which keyword imports a module?
Explanation: import loads ES modules.
Question 23: Which array method reduces values to one?
- map()
- filter()
- reduce()
- find()
Explanation: reduce() aggregates values.
Question 24: Which keyword exits a function immediately?
Explanation: return exits function execution.
Question 25: Which object provides math utilities?
Explanation: Math provides built-in math functions.
Question 26: Which method rounds a number down?
- Math.round()
- Math.ceil()
- Math.floor()
- Math.fix()
Explanation: Math.floor() rounds down.
Question 27: Which event fires when DOM is fully parsed?
- load
- ready
- DOMContentLoaded
- init
Explanation: DOMContentLoaded fires after DOM parsing.
Question 28: Which method selects all matching elements?
- getElementById()
- querySelector()
- querySelectorAll()
- selectAll()
Explanation: querySelectorAll() returns multiple elements.
Question 29: Which symbol defines arrow functions?
Explanation: => is used for arrow functions.
Question 30: Which Promise state indicates success?
- pending
- running
- fulfilled
- rejected
Explanation: fulfilled means resolved successfully.
Question 31: Which keyword pauses execution in async functions?
Explanation: await pauses execution until promise resolves.
Question 32: Which operator checks property existence?
Explanation: in checks if property exists.
Question 33: Which statement enables strict mode?
- use strict
- 'use strict'
- strict()
- enableStrict
Explanation: 'use strict' enables strict mode.
Question 34: Which array method checks all elements against a condition?
- some()
- filter()
- every()
- find()
Explanation: every() tests all elements.
Question 35: Which array method checks at least one element?
- some()
- every()
- map()
- reduce()
Explanation: some() tests at least one element.
Question 36: Which method returns key-value pairs of an object?
- Object.keys()
- Object.values()
- Object.entries()
- Object.items()
Explanation: Object.entries() returns key-value pairs.
Question 37: Which operator is used for optional chaining?
Explanation: Optional chaining prevents access errors.
Question 38: Which value is returned by a function by default?
Explanation: Functions return undefined by default.
Question 39: Which method converts a string to integer?
- Number()
- parseInt()
- Math.int()
- toInt()
Explanation: parseInt() converts string to integer.
Question 40: Which array method removes elements by index?
- slice()
- pop()
- shift()
- splice()
Explanation: splice() removes elements by index.
Question 41: Which keyword creates a Promise?
- Promise()
- async Promise
- new Promise
- create Promise
Explanation: Promises are created using new Promise().
Question 42: Which structure preserves insertion order?
Explanation: Map preserves insertion order.
Question 43: Which API blocks the main thread?
- fetch()
- setTimeout()
- alert()
- Promise
Explanation: alert() blocks the main thread.
Question 44: Which statement about this is true in strict mode?
- this refers to window
- this is global
- this is undefined
- this is null
Explanation: In strict mode, this is undefined.
Question 45: Which method flattens nested arrays?
- concat()
- flat()
- reduce()
- spread
Explanation: flat() flattens nested arrays.
Question 46: Which operator increments a value by one?
Explanation: ++ increments a value by one.
Question 47: Which JavaScript feature allows lazy execution?
- Promises
- Generators
- Closures
- Callbacks
Explanation: Generators support lazy execution.
Question 48: Which keyword pauses generator execution?
Explanation: yield pauses generator execution.