Q. Which one will return 'true'?

Code:
console.log([] == ![]);
  • (A) true
  • (B) false
  • (C) undefined
  • (D) NaN
πŸ’¬ Discuss
βœ… Correct Answer: (A) true
Explanation: [] is truthy, so ![] is false. [] == false evaluates to true due to coercion.

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

  • (A) map()
  • (B) filter()
  • (C) forEach()
  • (D) every()
πŸ’¬ Discuss
βœ… Correct Answer: (A) map()
Explanation: map() returns a new array after applying a function to each element.

Q. What will be logged?

Code:
console.log('2' - '1');
  • (A) 1
  • (B) 11
  • (C) NaN
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1
Explanation: The - operator coerces both strings to numbers.

Q. How can you prevent a default event action in JavaScript?

  • (A) event.block()
  • (B) event.preventDefault()
  • (C) event.stop()
  • (D) event.cancel()
πŸ’¬ Discuss
βœ… Correct Answer: (B) event.preventDefault()
Explanation: event.preventDefault() stops the default behavior of an event.

Q. What is the output?

Code:
console.log(typeof []);
  • (A) object
  • (B) array
  • (C) list
  • (D) undefined
πŸ’¬ Discuss
βœ… Correct Answer: (A) object
Explanation: Arrays are technically objects in JavaScript.

Q. What will this return?

Code:
[1, 2, 3].reduce((a, b) => a + b);
  • (A) 6
  • (B) 1
  • (C) [1, 2, 3]
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 6
Explanation: reduce sums the elements: 1 + 2 + 3 = 6.

Q. What does the following return?

Code:
console.log(typeof null);
  • (A) null
  • (B) object
  • (C) undefined
  • (D) NaN
πŸ’¬ Discuss
βœ… Correct Answer: (B) object
Explanation: typeof null returns 'object' due to a historical bug in JavaScript.

Q. Which of these is not a looping structure in JavaScript?

  • (A) for
  • (B) foreach
  • (C) while
  • (D) do...while
πŸ’¬ Discuss
βœ… Correct Answer: (B) foreach
Explanation: JavaScript has forEach (as a method), not a foreach loop structure.

Q. What will the code output?

Code:
console.log([] + []);
  • (A) []
  • (B) undefined
  • (C) NaN
  • (D) ""
πŸ’¬ Discuss
βœ… Correct Answer: (D) ""
Explanation: [] + [] results in an empty string because both are coerced to strings.

Q. What is the purpose of the isNaN() function?

  • (A) Checks if a value is NaN
  • (B) Checks if a value is not a number
  • (C) Checks if a value is null
  • (D) Both a and b
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both a and b
Explanation: isNaN() returns true if the value is NaN or not a number.