JavaScript - MCQ Questions and Answers

Test your knowledge of JavaScript with these interactive multiple-choice questions.

« First 7 8 9 10 Last »
« Previous Page Next Page »

161. What is the output of console.log(1 + +"1")?

  • a) 2
  • b) "11"
  • c) NaN
  • d) TypeError
Answer: A - The unary + converts "1" to a number, resulting in 1 + 1 = 2.

162. Which method creates a new array with elements that pass a test?

  • a) filter()
  • b) map()
  • c) reduce()
  • d) forEach()
Answer: A - filter() returns a new array with elements that satisfy the condition.

163. What is the output of console.log([] == 0)?

  • a) true
  • b) false
  • c) TypeError
  • d) undefined
Answer: A - The empty array [] is converted to 0 during loose equality comparison.

164. Which method executes a reducer function on each element?

  • a) reduce()
  • b) map()
  • c) filter()
  • d) some()
Answer: A - reduce() accumulates a single result from the array.

165. What is the output of console.log("5" - 3)?

  • a) 2
  • b) "53"
  • c) NaN
  • d) TypeError
Answer: A - The - operator coerces "5" to a number, resulting in numeric subtraction.

166. Which method checks if at least one element passes a test?

  • a) some()
  • b) every()
  • c) includes()
  • d) find()
Answer: A - some() returns true if any element satisfies the condition.

167. What is the output of console.log(typeof NaN)?

  • a) "number"
  • b) "NaN"
  • c) "undefined"
  • d) "string"
Answer: A - NaN is technically of type "number" despite meaning "Not a Number".

168. Which method returns the last index of an element in an array?

  • a) lastIndexOf()
  • b) findLastIndex()
  • c) searchLast()
  • d) indexOf() with reverse iteration
Answer: A - lastIndexOf() searches from the end of the array.

169. What is the output of console.log(+"Infinity")?

  • a) Infinity (number type)
  • b) "Infinity" (string)
  • c) NaN
  • d) TypeError
Answer: A - The unary + converts the string "Infinity" to the number Infinity.

170. Which method returns the primitive value of an object?

  • a) valueOf()
  • b) toString()
  • c) toPrimitive()
  • d) Symbol.toPrimitive
Answer: A - valueOf() is called when an object needs to be converted to a primitive value.

171. What is the output of console.log(1 == "1")?

  • a) true
  • b) false
  • c) NaN
  • d) "11"
Answer: A - Loose equality (==) performs type coercion, converting the string "1" to the number 1.

172. Which statement about let and const is true?

  • a) Both are block-scoped
  • b) Both are hoisted to the function scope
  • c) const allows reassignment
  • d) let doesn't support temporal dead zone
Answer: A - let and const are block-scoped and hoisted but cannot be accessed before declaration (temporal dead zone).

173. What is the output of console.log(typeof (function(){}()))?

  • a) "undefined"
  • b) "function"
  • c) "object"
  • d) "null"
Answer: A - The IIFE (Immediately Invoked Function Expression) returns nothing, so its type is undefined.

174. Which method creates a new array with all sub-array elements concatenated recursively?

  • a) flat()
  • b) flatMap()
  • c) concat()
  • d) join()
Answer: A - flat(depth) flattens nested arrays up to the specified depth (default: 1).

175. What does console.log(new String("test") === "test") output?

  • a) false
  • b) true
  • c) TypeError
  • d) undefined
Answer: A - The String object and primitive string are of different types (object vs string).

176. Which operator has the highest precedence?

  • a) () (grouping)
  • b) . (member access)
  • c) new (with argument list)
  • d) ++ (postfix increment)
Answer: A - Grouping () has the highest precedence, followed by member access . and new.

177. What is the output of console.log(!!new Boolean(false))?

  • a) true
  • b) false
  • c) "false"
  • d) TypeError
Answer: A - new Boolean(false) is an object (truthy), so !! converts it to true.

178. Which method prevents extensions to an object?

  • a) Object.preventExtensions()
  • b) Object.seal()
  • c) Object.freeze()
  • d) All of the above
Answer: A - Object.preventExtensions() disables adding new properties (but allows modifying/deleting existing ones).

179. What is the output of console.log(+"")?

  • a) 0
  • b) NaN
  • c) ""
  • d) TypeError
Answer: A - The unary + coerces an empty string to 0.

180. Which method returns the first element that satisfies a condition?

  • a) find()
  • b) filter()
  • c) some()
  • d) indexOf()
Answer: A - find() returns the first matching element (or undefined if none).
« First 7 8 9 10 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.