JavaScript - MCQ Questions and Answers

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

« First 3 4 5 6 Last »
« Previous Page Next Page »

61. What is the output of console.log([] + {})?

  • a) "[object Object]"
  • b) "{}"
  • c) TypeError
  • d) 0
Answer: A - The array converts to an empty string, and the object to "[object Object]", resulting in concatenation.

62. Which method executes a function after a specified delay?

  • a) setTimeout()
  • b) setInterval()
  • c) queueMicrotask()
  • d) process.nextTick()
Answer: A - setTimeout() schedules a one-time execution after the delay (in milliseconds).

63. What is the prototype of an object created with Object.create(null)?

  • a) null (no prototype)
  • b) Object.prototype
  • c) undefined
  • d) Array.prototype
Answer: A - Object.create(null) creates an object with no prototype chain.

64. What does console.log(+"Infinity") output?

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

65. 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.

66. 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.

67. 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).

68. 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.

69. 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).

70. 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).

71. 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.

72. 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.

73. 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).

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

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

75. 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).

76. What is the output of console.log(3 > 2 > 1)?

  • a) false
  • b) true
  • c) TypeError
  • d) undefined
Answer: A - Evaluated as (3 > 2) > 1true > 11 > 1false.

77. Which symbol is used as a placeholder for awaiting promises?

  • a) await
  • b) async
  • c) then
  • d) yield
Answer: A - await pauses execution until a promise settles (must be inside an async function).

78. What is the output of console.log(Number("123abc"))?

  • a) NaN
  • b) 123
  • c) "123abc"
  • d) TypeError
Answer: A - Number() returns NaN for strings with non-numeric characters.

79. Which method returns a string representation of an array?

  • a) toString()
  • b) join()
  • c) String()
  • d) All of the above
Answer: D - All three methods convert arrays to strings, but join() allows custom separators.

80. What is the output of console.log(typeof class {})?

  • a) "function"
  • b) "class"
  • c) "object"
  • d) "undefined"
Answer: A - Classes are syntactic sugar over constructor functions, so their type is "function".
« First 3 4 5 6 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.