JavaScript Quiz (Intermediate) - All Questions
This JavaScript Intermediate Quiz is designed for developers who already understand the basics and want to test real-world JavaScript concepts. It covers arrays, objects, functions, scope, DOM manipulation, async behavior, and interview-relevant logic.
Question 1: What is the scope of a variable declared using let?
- Global scope
- Function scope
- Block scope
- Module scope
Explanation: Variables declared with let are block-scoped.
Question 2: Which array method returns a new array without modifying the original?
- splice()
- slice()
- push()
- pop()
Explanation: slice() returns a shallow copy of an array.
Question 3: What will typeof NaN return?
Explanation: NaN is considered a number type in JavaScript.
Question 4: Which operator checks both value and type equality?
Explanation: === checks both value and data type.
Question 5: Which method converts a NodeList to an array?
- Array.from()
- toArray()
- convert()
- map()
Explanation: Array.from() converts iterable objects to arrays.
Question 6: Which keyword prevents reassignment but allows object mutation?
Explanation: const prevents reassignment but allows mutation.
Question 7: Which array method is used to transform each element?
- filter()
- reduce()
- map()
- find()
Explanation: map() transforms each array element.
Question 8: Which array method returns the first matching element?
- filter()
- find()
- map()
- every()
Explanation: find() returns the first matching element.
Question 9: What is the default value of an unassigned function parameter?
Explanation: Unassigned parameters are undefined.
Question 10: Which method stops event bubbling?
- preventDefault()
- stop()
- stopPropagation()
- cancel()
Explanation: stopPropagation() prevents event bubbling.
Question 11: Which keyword refers to the global object in browsers?
Explanation: window is the global object in browsers.
Question 12: Which loop is preferred when the number of iterations is unknown?
Explanation: while loops run based on condition.
Question 13: Which operator spreads array elements?
Explanation: The spread operator expands iterable elements.
Question 14: Which block always executes whether an error occurs or not?
Explanation: finally always executes.
Question 15: Which method checks if an array contains a value?
- has()
- includes()
- exists()
- contains()
Explanation: includes() checks for value existence.
Question 16: Which function executes code once after a delay?
- setInterval()
- delay()
- setTimeout()
- wait()
Explanation: setTimeout() executes code after a delay.
Question 17: Which function executes code repeatedly at intervals?
- setTimeout()
- repeat()
- setInterval()
- loop()
Explanation: setInterval() repeats execution.
Question 18: Which method merges two arrays into one?
- join()
- merge()
- concat()
- push()
Explanation: concat() merges arrays.
Question 19: Which keyword is used to define a class?
- object
- function
- class
- constructor
Explanation: class keyword defines a class.
Question 20: Which method returns all keys of an object?
- Object.values()
- Object.entries()
- Object.keys()
- Object.get()
Explanation: Object.keys() returns property names.
Question 21: Which method makes an object immutable?
- Object.seal()
- Object.freeze()
- Object.lock()
- const
Explanation: Object.freeze() prevents modifications.
Question 22: Which keyword is used for inheritance in classes?
- super
- inherits
- extends
- prototype
Explanation: extends creates inheritance.
Question 23: Which keyword calls the parent class constructor?
- this()
- parent()
- super()
- base()
Explanation: super() calls the parent constructor.
Question 24: Which operator handles null or undefined values?
Explanation: Nullish coalescing handles null or undefined.
Question 25: Which method removes whitespace from both ends of a string?
- strip()
- trim()
- clean()
- cut()
Explanation: trim() removes leading and trailing spaces.
Question 26: Which keyword exports a module?
Explanation: export makes module members available.
Question 27: Which keyword imports a module?
Explanation: import loads modules.
Question 28: Which method reduces an array to a single value?
- map()
- filter()
- reduce()
- find()
Explanation: reduce() aggregates array values.
Question 29: Which keyword exits a function immediately?
Explanation: return exits function execution.
Question 30: Which object provides mathematical functions?
Explanation: Math provides built-in math utilities.
Question 31: Which method rounds a number down?
- Math.round()
- Math.ceil()
- Math.floor()
- Math.fix()
Explanation: Math.floor() rounds down.
Question 32: Which event fires when the DOM is fully loaded?
- load
- ready
- DOMContentLoaded
- init
Explanation: DOMContentLoaded fires after DOM parsing.
Question 33: Which method selects all matching elements?
- getElementById()
- querySelector()
- querySelectorAll()
- selectAll()
Explanation: querySelectorAll() returns all matching nodes.
Question 34: Which symbol defines an arrow function?
Explanation: => is used in arrow functions.
Question 35: Which feature handles asynchronous operations?
- Callbacks
- Promises
- Async/Await
- All of the above
Explanation: All listed options handle async operations.
Question 36: Which Promise state indicates success?
- pending
- running
- fulfilled
- rejected
Explanation: fulfilled means the promise resolved.
Question 37: Which keyword pauses execution in async functions?
Explanation: await pauses execution until resolved.
Question 38: Which operator checks if a property exists in an object?
Explanation: in checks property existence.
Question 39: Which statement enables strict mode?
- use strict
- 'use strict'
- strict()
- enableStrict
Explanation: 'use strict' enables strict mode.
Question 40: Which array method tests all elements against a condition?
- some()
- every()
- filter()
- find()
Explanation: every() checks all elements.
Question 41: Which array method checks at least one element?
- some()
- every()
- map()
- reduce()
Explanation: some() checks at least one element.
Question 42: 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 43: Which operator is used for optional chaining?
Explanation: Optional chaining prevents runtime errors.
Question 44: Which value does a function return by default?
Explanation: Functions return undefined by default.
Question 45: Which method converts a value to an integer?
- Number()
- parseInt()
- Math.int()
- toInt()
Explanation: parseInt() converts to integer.
Question 46: Which keyword defines block-level scope?
Explanation: let is block-scoped.
Question 47: Which operator increments a value by one?
Explanation: ++ increments by one.
Question 48: Which array method removes elements by index?
- slice()
- pop()
- shift()
- splice()
Explanation: splice() removes elements by index.
Question 49: Which keyword creates a Promise?
- new Promise
- Promise()
- create Promise
- async Promise
Explanation: Promises are created using new Promise().