41. What is the output of console.log(typeof NaN)?
- a) "number"
- b) "NaN"
- c) "undefined"
- d) "string"
NaN is technically of type "number".
Test your knowledge of JavaScript with these interactive multiple-choice questions.
41. What is the output of console.log(typeof NaN)?
NaN is technically of type "number".
42. Which method creates a new array with transformed elements?
map() applies a function to each element and returns a new array.
43. What does document.querySelector() return if no match is found?
null when no matching element exists in the DOM.
44. Which operator is used for exponentiation in JavaScript?
**) raises a base to a power (e.g., 2 ** 3 → 8).
45. What is the output of console.log([] == ![])?
false ([] becomes "" then 0, ![] becomes false then 0).
46. Which method converts an array to a string?
join() allows custom separators.
47. What is the purpose of the finally block in a try-catch?
finally runs whether the try succeeds or fails, useful for cleanup.
48. What does console.log(!!0) output?
0 is falsy, so !!0 converts it to boolean false.
49. Which method returns the first index where an element is found in an array?
indexOf() (for primitive values) and findIndex() (for complex conditions) return the first matching index.
50. What is the output of console.log("b" + "a" + +"a" + "a")?
+ coerces "a" to NaN, resulting in concatenation: "b" + "a" + "NaN" + "a".
51. Which statement about const is true?
const requires initialization and cannot be reassigned (though object properties can be modified).
52. What is the output of console.log(0.1 + 0.2)?
0.3).
53. Which method checks if an object has a specific property?
hasOwnProperty() checks for non-inherited properties, while in includes inherited ones.
54. What does console.log(typeof (() => {})) output?
"function".
55. Which method delays execution until the call stack is clear?
nextTick() > setImmediate() > setTimeout() in Node.js).
56. What is the output of console.log(new Boolean(false))?
new Boolean(false) creates a truthy object wrapper, not a primitive.
57. Which method creates a shallow copy of an object?
Object.assign() and the spread operator create shallow copies.
58. What is the output of console.log(1 < 2 < 3)?
(1 < 2) < 3 → true < 3 → 1 < 3 → true.
59. Which method reverses an array in place?
reverse() mutates the original array. toReversed() (new in ES2023) returns a new reversed array.
60. What does console.log(+"") output?
+ coerces an empty string to 0.