JavaScript - MCQ Questions and Answers

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

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

81. What is the output of console.log(+"0x10")?

  • a) 16
  • b) "0x10"
  • c) 10
  • d) NaN
Answer: A - The unary + converts hexadecimal "0x10" to decimal 16.

82. Which method creates a new array with the results of calling a function on every element?

  • a) map()
  • b) forEach()
  • c) filter()
  • d) reduce()
Answer: A - map() transforms each element and returns a new array.

83. What is the output of console.log(typeof (() => {}))?

  • a) "function"
  • b) "object"
  • c) "arrow"
  • d) "undefined"
Answer: A - Arrow functions are still of type "function".

84. Which operator returns the remainder of a division?

  • a) %
  • b) /
  • c) mod
  • d) rem
Answer: A - The modulo operator (%) returns the remainder (e.g., 10 % 31).

85. What is the output of console.log(0 || "Hello")?

  • a) "Hello"
  • b) 0
  • c) true
  • d) false
Answer: A - The logical OR (||) returns the first truthy value ("Hello" in this case).

86. Which method checks if an array includes a value?

  • a) includes()
  • b) contains()
  • c) indexOf()
  • d) find()
Answer: A - includes() returns true if the value exists in the array.

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

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

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

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

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

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

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

93. 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".

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

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

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

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

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

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

100. 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).
« First 4 5 6 7 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.